Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YEL-109 [deploy] , 제거 및 첫쪽지 배포 #184

Merged
merged 7 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
import com.yello.server.domain.friend.repository.FriendRepository;
import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.repository.SchoolRepository;
import com.yello.server.domain.question.entity.Question;
import com.yello.server.domain.question.repository.QuestionRepository;
import com.yello.server.domain.user.entity.Gender;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.exception.UserConflictException;
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.entity.Vote;
import com.yello.server.domain.vote.repository.VoteRepository;
import com.yello.server.global.common.factory.ListFactory;
import com.yello.server.global.common.factory.PaginationFactory;
import com.yello.server.global.common.util.RestUtil;
Expand Down Expand Up @@ -62,12 +67,14 @@ public class AuthService {
private final SchoolRepository schoolRepository;
private final FriendRepository friendRepository;
private final CooldownRepository cooldownRepository;
private final QuestionRepository questionRepository;
private final VoteRepository voteRepository;
private final JwtTokenProvider jwtTokenProvider;
private final TokenRepository tokenValueOperations;

// TODO softDelete 우아하게 처리하는 방법으로 바꾸기
public Boolean renewUserInformation(User currentUser) {
if (currentUser.getDeletedAt() != null) {
if (currentUser.getDeletedAt()!=null) {
currentUser.renew();

friendRepository.findAllByUserIdNotFiltered(currentUser.getId())
Expand All @@ -89,7 +96,7 @@ public OAuthResponse oauthLogin(OAuthRequest oAuthRequest) {
final ResponseEntity<KakaoTokenInfo> response = RestUtil.getKakaoTokenInfo(
oAuthRequest.accessToken());

if (response.getStatusCode() == BAD_REQUEST || response.getStatusCode() == UNAUTHORIZED) {
if (response.getStatusCode()==BAD_REQUEST || response.getStatusCode()==UNAUTHORIZED) {
throw new OAuthException(OAUTH_TOKEN_EXCEPTION);
}

Expand Down Expand Up @@ -118,11 +125,17 @@ public Boolean isYelloIdDuplicated(String yelloId) {

@Transactional
public SignUpResponse signUp(SignUpRequest signUpRequest) {
String greetingNameHead = null;
String greetingNameFoot = "에게 옐로가 전할 말은";
String greetingKeywordHead = null;
String greetingKeywordFoot = "라는 말이야";

final User signUpUser = this.signUpUser(signUpRequest);
this.recommendUser(signUpRequest.recommendId());
final ServiceTokenVO signUpToken =
this.registerToken(signUpUser.getId(), signUpUser.getUuid());
this.makeFriend(signUpUser, signUpRequest.friends());
this.makeGreetingVote(signUpUser, greetingNameHead, greetingNameFoot, greetingKeywordHead, greetingKeywordFoot);

return SignUpResponse.of(signUpUser.getYelloId(), signUpToken);
}
Expand All @@ -147,7 +160,7 @@ public User signUpUser(SignUpRequest signUpRequest) {
}

public void recommendUser(String recommendYelloId) {
if (recommendYelloId != null && !recommendYelloId.isEmpty()) {
if (recommendYelloId!=null && !recommendYelloId.isEmpty()) {
User recommendedUser = userRepository.getByYelloId(recommendYelloId);
recommendedUser.increaseRecommendCount();

Expand Down Expand Up @@ -179,6 +192,33 @@ public void makeFriend(User user, List<Long> friendIds) {
});
}

public void makeGreetingVote(User user, String greetingNameHead, String greetingNameFoot,
String greetingKeywordHead, String greetingKeywordFoot) {
String yelloMaleId = "yello_male";
String yelloFemaleId = "yello_female";

final User yelloGreetingMale = userRepository.findByUuid(yelloMaleId)
.orElseGet(() ->
userRepository.save(User.yelloGreeting(yelloMaleId, Gender.MALE))
);
final User yelloGreetingFemale = userRepository.findByUuid(yelloFemaleId)
.orElseGet(() ->
userRepository.save(User.yelloGreeting(yelloFemaleId, Gender.FEMALE))
);

final User sender = (user.getGender()==Gender.MALE) ? yelloGreetingFemale : yelloGreetingMale;

final Question greetingQuestion = questionRepository.findByQuestionContent(greetingNameHead, greetingNameFoot,
greetingKeywordHead, greetingKeywordFoot)
.orElseGet(() ->
questionRepository.save(
Question.of(greetingNameHead, greetingNameFoot, greetingKeywordHead, greetingKeywordFoot))
);

voteRepository.save(Vote.createFirstVote("널 기다렸어", sender, user, greetingQuestion));
}


public OnBoardingFriendResponse findOnBoardingFriends(OnBoardingFriendRequest friendRequest,
Pageable pageable) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public interface FriendJpaRepository extends JpaRepository<Friend, Long> {
Optional<Friend> findByUserAndTarget(@Param("userId") Long userId,
@Param("targetId") Long targetId);

@Query("select f from Friend f " +
"where f.target.id = :targetId " +
"and f.user.id = :userId")
Optional<Friend> findByUserAndTargetNotFiltered(Long userId, Long targetId);

@Query("select case when count(f) > 0 then true else false end from Friend f " +
"where f.target.id = :targetId " +
"and f.user.id = :userId " +
Expand Down Expand Up @@ -59,5 +64,4 @@ Optional<Friend> findByUserAndTarget(@Param("userId") Long userId,
@Query("select f from Friend f " +
"where f.target.id = :targetId")
List<Friend> findAllByTargetIdNotFiltered(Long targetId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public interface FriendRepository {

Optional<Friend> findByUserAndTarget(Long userId, Long targetId);

Optional<Friend> findByUserAndTargetNotFiltered(Long userId, Long targetId);

Friend getByUserAndTarget(Long userId, Long targetId);

boolean existsByUserAndTarget(Long userId, Long targetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Optional<Friend> findByUserAndTarget(Long userId, Long targetId) {
return friendJpaRepository.findByUserAndTarget(userId, targetId);
}

@Override
public Optional<Friend> findByUserAndTargetNotFiltered(Long userId, Long targetId) {
return friendJpaRepository.findByUserAndTargetNotFiltered(userId, targetId);
}

@Override
public Friend getByUserAndTarget(Long userId, Long targetId) {
return friendJpaRepository.findByUserAndTarget(userId, targetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ private static String deleteBracket(String target) {
return slashIndex!=-1 ? target.substring(slashIndex + 1) : target;
}

public static Question of(String nameHead, String nameFoot, String keywordHead, String keywordFoot) {
return Question.builder()
.nameHead(nameHead)
.nameFoot(nameFoot)
.keywordHead(keywordHead)
.keywordFoot(keywordFoot)
.build();
}

public void addKeyword(Keyword keyword) {
this.keywordList.add(keyword);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.yello.server.domain.question.repository;

import com.yello.server.domain.question.entity.Question;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface QuestionJpaRepository extends JpaRepository<Question, Long> {

}
@Query("select q from Question q "
+ "where (COALESCE(:nameHead, '') = '' OR q.nameHead is null OR q.nameHead = :nameHead) "
+ "and (COALESCE(:nameFoot, '') = '' OR q.nameFoot is null OR q.nameFoot = :nameFoot) "
+ "and (COALESCE(:keywordHead, '') = '' OR q.keywordHead is null OR q.keywordHead = :keywordHead) "
+ "and (COALESCE(:keywordFoot, '') = '' OR q.keywordFoot is null OR q.keywordFoot = :keywordFoot)")
Optional<Question> findByQuestionContent(@Param("nameHead") String nameHead, @Param("nameFoot") String nameFoot,
@Param("keywordHead") String keywordHead, @Param("keywordFoot") String keywordFoot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.yello.server.domain.question.entity.Question;
import java.util.List;
import java.util.Optional;

public interface QuestionRepository {

Expand All @@ -10,4 +11,6 @@ public interface QuestionRepository {
Question findById(Long id);

Question save(Question question);

Optional<Question> findByQuestionContent(String nameHead, String nameFoot, String keywordHead, String keywordFoot);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.yello.server.domain.question.entity.Question;
import com.yello.server.domain.question.exception.QuestionException;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -31,4 +32,10 @@ public Question findById(Long id) {
public Question save(Question question) {
return questionJpaRepository.save(question);
}

@Override
public Optional<Question> findByQuestionContent(String nameHead, String nameFoot, String keywordHead,
String keywordFoot) {
return questionJpaRepository.findByQuestionContent(nameHead, nameFoot, keywordHead, keywordFoot);
}
}
20 changes: 20 additions & 0 deletions src/main/java/com/yello/server/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ public static User of(SignUpRequest signUpRequest, School group) {
.build();
}

public static User yelloGreeting(String yelloId, Gender gender) {
return User.builder()
.recommendCount(0L)
.name(yelloId)
.yelloId(yelloId)
.gender(gender)
.point(0)
.social(Social.KAKAO)
.profileImage("")
.uuid(yelloId)
.deletedAt(null)
.group(null)
.groupAdmissionYear(0)
.email("")
.deviceToken(yelloId)
.subscribe(Subscribe.NORMAL)
.ticketCount(0)
.build();
}

public void delete() {
this.deletedAt = LocalDateTime.now();
this.point = 0;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/yello/server/domain/vote/entity/Vote.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yello.server.domain.question.entity.Question;
import com.yello.server.domain.user.entity.User;
import com.yello.server.global.common.dto.AuditingTimeEntity;
import java.util.Random;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
Expand Down Expand Up @@ -77,6 +78,21 @@ public static Vote createVote(String answer, User sender, User receiver, Questio
return Vote.of(answer, sender, receiver, question, colorIndex);
}

public static Vote createFirstVote(String answer, User sender, User receiver, Question question) {
Random random = new Random();

return Vote.builder()
.answer(answer)
.nameHint(3)
.isAnswerRevealed(true)
.isRead(false)
.sender(sender)
.receiver(receiver)
.question(question)
.colorIndex(random.nextInt(12) + 1)
.build();
}

public void checkKeyword() {
this.isAnswerRevealed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public interface VoteJpaRepository extends JpaRepository<Vote, Long> {
+ "and v.receiver.deletedAt is null "
+ "order by v.createdAt desc")
Integer countAllReceivedByFriends(@Param("userId") Long userId);

}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.yello.server.infrastructure.firebase.dto.request.NotificationMessage;
import com.yello.server.infrastructure.firebase.manager.FCMManager;
import com.yello.server.infrastructure.redis.repository.TokenRepository;
import java.text.MessageFormat;
import lombok.Builder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -28,7 +27,7 @@ public void sendYelloNotification(Vote vote) {

NotificationMessage notificationMessage = NotificationMessage.toYelloNotificationContent(vote);

final String path = MessageFormat.format("/api/v1/vote/{0}", vote.getId());
final String path = "/api/v1/vote/" + vote.getId().toString();
final Message message = fcmManager.createMessage(receiver.getDeviceToken(), notificationMessage, path);

fcmManager.send(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@
import com.yello.server.domain.group.entity.School;
import com.yello.server.domain.group.exception.GroupNotFoundException;
import com.yello.server.domain.group.repository.SchoolRepository;
import com.yello.server.domain.question.entity.Question;
import com.yello.server.domain.question.repository.QuestionRepository;
import com.yello.server.domain.user.entity.Gender;
import com.yello.server.domain.user.entity.Social;
import com.yello.server.domain.user.entity.User;
import com.yello.server.domain.user.exception.UserConflictException;
import com.yello.server.domain.user.repository.UserRepository;
import com.yello.server.domain.vote.repository.VoteRepository;
import com.yello.server.global.common.factory.PaginationFactory;
import com.yello.server.infrastructure.redis.repository.TokenRepository;
import com.yello.server.small.domain.cooldown.FakeCooldownRepository;
import com.yello.server.small.domain.friend.FakeFriendRepository;
import com.yello.server.small.domain.group.FakeSchoolRepository;
import com.yello.server.small.domain.question.FakeQuestionRepository;
import com.yello.server.small.domain.user.FakeUserRepository;
import com.yello.server.small.domain.vote.FakeVoteRepository;
import com.yello.server.small.global.redis.FakeTokenRepository;
import java.time.LocalDateTime;
import java.util.ArrayList;
Expand All @@ -51,6 +56,8 @@ public class AuthServiceTest {
private final SchoolRepository schoolRepository = new FakeSchoolRepository();
private final FriendRepository friendRepository = new FakeFriendRepository();
private final CooldownRepository cooldownRepository = new FakeCooldownRepository();
private final QuestionRepository questionRepository = new FakeQuestionRepository();
private final VoteRepository voteRepository = new FakeVoteRepository();
private final JwtTokenProvider jwtTokenProvider = new JwtTokenProvider(secretKey);
private final TokenRepository tokenRepository = new FakeTokenRepository();
private AuthService authService;
Expand All @@ -62,6 +69,8 @@ void init() {
.schoolRepository(schoolRepository)
.friendRepository(friendRepository)
.cooldownRepository(cooldownRepository)
.questionRepository(questionRepository)
.voteRepository(voteRepository)
.jwtTokenProvider(jwtTokenProvider)
.tokenValueOperations(tokenRepository)
.build();
Expand Down Expand Up @@ -403,4 +412,28 @@ void init() {
.sorted()
.toList());
}

@Test
void 회원가입_첫쪽지_생성에_성공합니다() {
// given
Long userId = 1L;
String greetingNameHead = null;
String greetingNameFoot = "에게 옐로가 전할 말은";
String greetingKeywordHead = null;
String greetingKeywordFoot = "라는 말이야";

// when
final User user = userRepository.getById(userId);
authService.makeGreetingVote(user, greetingNameHead, greetingNameFoot, greetingKeywordHead,
greetingKeywordFoot);
final Optional<Question> question = questionRepository.findByQuestionContent(greetingNameHead,
greetingNameFoot, greetingKeywordHead, greetingKeywordFoot);

// then
assertThat(question.isPresent()).isEqualTo(true);
assertThat(question.get().getNameHead()).isEqualTo(greetingNameHead);
assertThat(question.get().getNameFoot()).isEqualTo(greetingNameFoot);
assertThat(question.get().getKeywordHead()).isEqualTo(greetingKeywordHead);
assertThat(question.get().getKeywordFoot()).isEqualTo(greetingKeywordFoot);
}
}
Loading