From 9d1b0f0e1f617011ca66d7419f5d204c19eb1901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=98=EC=A0=9C?= Date: Sun, 13 Aug 2023 19:05:27 +0900 Subject: [PATCH 1/4] =?UTF-8?q?YEL-96=20[feat]=20friend=20delete=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/small/domain/friend/FakeFriendRepository.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java index 825fc044..7406bc05 100644 --- a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java +++ b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java @@ -34,6 +34,11 @@ public Friend save(Friend friend) { return newFriend; } + @Override + public void delete(Friend friend) { + data.remove(friend); + } + @Override public Integer countAllByUserId(Long userId) { return data.stream() From 28df3eb47576bcbf93d4e15f1fa491fc7436f781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=98=EC=A0=9C?= Date: Sun, 13 Aug 2023 19:05:50 +0900 Subject: [PATCH 2/4] =?UTF-8?q?YEL-96=20[feat]=20=EC=B2=AB=20=EC=AA=BD?= =?UTF-8?q?=EC=A7=80=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorization/service/AuthService.java | 46 +++++++++++++++++-- .../domain/question/entity/Question.java | 9 ++++ .../repository/QuestionJpaRepository.java | 12 ++++- .../repository/QuestionRepository.java | 3 ++ .../repository/QuestionRepositoryImpl.java | 7 +++ .../yello/server/domain/user/entity/User.java | 20 ++++++++ .../yello/server/domain/vote/entity/Vote.java | 16 +++++++ .../vote/repository/VoteJpaRepository.java | 1 + .../domain/authorization/AuthServiceTest.java | 33 +++++++++++++ .../question/FakeQuestionRepository.java | 13 ++++++ 10 files changed, 156 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/yello/server/domain/authorization/service/AuthService.java b/src/main/java/com/yello/server/domain/authorization/service/AuthService.java index b787a464..02310416 100644 --- a/src/main/java/com/yello/server/domain/authorization/service/AuthService.java +++ b/src/main/java/com/yello/server/domain/authorization/service/AuthService.java @@ -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; @@ -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()) @@ -89,7 +96,7 @@ public OAuthResponse oauthLogin(OAuthRequest oAuthRequest) { final ResponseEntity 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); } @@ -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); } @@ -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(); @@ -179,6 +192,33 @@ public void makeFriend(User user, List 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) { diff --git a/src/main/java/com/yello/server/domain/question/entity/Question.java b/src/main/java/com/yello/server/domain/question/entity/Question.java index 6659f649..31142121 100644 --- a/src/main/java/com/yello/server/domain/question/entity/Question.java +++ b/src/main/java/com/yello/server/domain/question/entity/Question.java @@ -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); } diff --git a/src/main/java/com/yello/server/domain/question/repository/QuestionJpaRepository.java b/src/main/java/com/yello/server/domain/question/repository/QuestionJpaRepository.java index cd6c821d..81065ca9 100644 --- a/src/main/java/com/yello/server/domain/question/repository/QuestionJpaRepository.java +++ b/src/main/java/com/yello/server/domain/question/repository/QuestionJpaRepository.java @@ -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 { -} + @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 findByQuestionContent(@Param("nameHead") String nameHead, @Param("nameFoot") String nameFoot, + @Param("keywordHead") String keywordHead, @Param("keywordFoot") String keywordFoot); +} \ No newline at end of file diff --git a/src/main/java/com/yello/server/domain/question/repository/QuestionRepository.java b/src/main/java/com/yello/server/domain/question/repository/QuestionRepository.java index 41105510..81802810 100644 --- a/src/main/java/com/yello/server/domain/question/repository/QuestionRepository.java +++ b/src/main/java/com/yello/server/domain/question/repository/QuestionRepository.java @@ -2,6 +2,7 @@ import com.yello.server.domain.question.entity.Question; import java.util.List; +import java.util.Optional; public interface QuestionRepository { @@ -10,4 +11,6 @@ public interface QuestionRepository { Question findById(Long id); Question save(Question question); + + Optional findByQuestionContent(String nameHead, String nameFoot, String keywordHead, String keywordFoot); } diff --git a/src/main/java/com/yello/server/domain/question/repository/QuestionRepositoryImpl.java b/src/main/java/com/yello/server/domain/question/repository/QuestionRepositoryImpl.java index 57c5a849..eacb7c1b 100644 --- a/src/main/java/com/yello/server/domain/question/repository/QuestionRepositoryImpl.java +++ b/src/main/java/com/yello/server/domain/question/repository/QuestionRepositoryImpl.java @@ -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; @@ -31,4 +32,10 @@ public Question findById(Long id) { public Question save(Question question) { return questionJpaRepository.save(question); } + + @Override + public Optional findByQuestionContent(String nameHead, String nameFoot, String keywordHead, + String keywordFoot) { + return questionJpaRepository.findByQuestionContent(nameHead, nameFoot, keywordHead, keywordFoot); + } } diff --git a/src/main/java/com/yello/server/domain/user/entity/User.java b/src/main/java/com/yello/server/domain/user/entity/User.java index 8bb6977e..8cafdabb 100644 --- a/src/main/java/com/yello/server/domain/user/entity/User.java +++ b/src/main/java/com/yello/server/domain/user/entity/User.java @@ -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; diff --git a/src/main/java/com/yello/server/domain/vote/entity/Vote.java b/src/main/java/com/yello/server/domain/vote/entity/Vote.java index a8b3b265..403a3072 100644 --- a/src/main/java/com/yello/server/domain/vote/entity/Vote.java +++ b/src/main/java/com/yello/server/domain/vote/entity/Vote.java @@ -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; @@ -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; } diff --git a/src/main/java/com/yello/server/domain/vote/repository/VoteJpaRepository.java b/src/main/java/com/yello/server/domain/vote/repository/VoteJpaRepository.java index 3fedc313..b9608824 100644 --- a/src/main/java/com/yello/server/domain/vote/repository/VoteJpaRepository.java +++ b/src/main/java/com/yello/server/domain/vote/repository/VoteJpaRepository.java @@ -39,5 +39,6 @@ public interface VoteJpaRepository extends JpaRepository { + "and v.receiver.deletedAt is null " + "order by v.createdAt desc") Integer countAllReceivedByFriends(@Param("userId") Long userId); + } \ No newline at end of file diff --git a/src/test/java/com/yello/server/small/domain/authorization/AuthServiceTest.java b/src/test/java/com/yello/server/small/domain/authorization/AuthServiceTest.java index e94efeff..be36335c 100644 --- a/src/test/java/com/yello/server/small/domain/authorization/AuthServiceTest.java +++ b/src/test/java/com/yello/server/small/domain/authorization/AuthServiceTest.java @@ -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; @@ -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; @@ -62,6 +69,8 @@ void init() { .schoolRepository(schoolRepository) .friendRepository(friendRepository) .cooldownRepository(cooldownRepository) + .questionRepository(questionRepository) + .voteRepository(voteRepository) .jwtTokenProvider(jwtTokenProvider) .tokenValueOperations(tokenRepository) .build(); @@ -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 = 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); + } } diff --git a/src/test/java/com/yello/server/small/domain/question/FakeQuestionRepository.java b/src/test/java/com/yello/server/small/domain/question/FakeQuestionRepository.java index 47d785f1..8a3942c3 100644 --- a/src/test/java/com/yello/server/small/domain/question/FakeQuestionRepository.java +++ b/src/test/java/com/yello/server/small/domain/question/FakeQuestionRepository.java @@ -10,6 +10,8 @@ import com.yello.server.small.domain.keyword.FakeKeywordRepository; import java.util.ArrayList; import java.util.List; +import java.util.Objects; +import java.util.Optional; public class FakeQuestionRepository implements QuestionRepository { @@ -55,4 +57,15 @@ public Question save(Question question) { data.add(newQuestion); return newQuestion; } + + @Override + public Optional findByQuestionContent(String nameHead, String nameFoot, String keywordHead, + String keywordFoot) { + return data.stream() + .filter(question -> Objects.equals(question.getNameHead(), nameHead) + && Objects.equals(question.getNameFoot(), nameFoot) + && Objects.equals(question.getKeywordHead(), keywordHead) + && Objects.equals(question.getKeywordFoot(), keywordFoot)) + .findFirst(); + } } From 229fd21e8bec46798404ede559b9991ca170bdc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=98=EC=A0=9C?= Date: Sun, 13 Aug 2023 23:34:24 +0900 Subject: [PATCH 3/4] =?UTF-8?q?YEL-109=20[feat]=20,=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../firebase/service/NotificationFcmService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java index a6913a0e..3dd158f6 100644 --- a/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java +++ b/src/main/java/com/yello/server/infrastructure/firebase/service/NotificationFcmService.java @@ -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; @@ -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); From 47f6a698ba0fb42e24f0ba992e0340e24c65a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=98=EC=A0=9C?= Date: Sun, 13 Aug 2023 23:34:41 +0900 Subject: [PATCH 4/4] =?UTF-8?q?YEL-109=20[feat]=20fcm=20test=20dependency?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/FriendJpaRepository.java | 6 ++++- .../friend/repository/FriendRepository.java | 2 ++ .../repository/FriendRepositoryImpl.java | 5 ++++ .../domain/friend/FakeFriendRepository.java | 25 ++++++++++++------- .../domain/friend/FriendServiceTest.java | 5 ++-- .../small/domain/vote/VoteServiceTest.java | 5 ++++ .../rabbitmq/FakeMessageQueueRepository.java | 13 ++++++++++ .../global/rabbitmq/FakeProducerService.java | 19 ++++++++++++++ 8 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 src/test/java/com/yello/server/small/global/rabbitmq/FakeMessageQueueRepository.java create mode 100644 src/test/java/com/yello/server/small/global/rabbitmq/FakeProducerService.java diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java b/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java index e20a33e6..584a0138 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendJpaRepository.java @@ -26,6 +26,11 @@ public interface FriendJpaRepository extends JpaRepository { Optional 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 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 " + @@ -59,5 +64,4 @@ Optional findByUserAndTarget(@Param("userId") Long userId, @Query("select f from Friend f " + "where f.target.id = :targetId") List findAllByTargetIdNotFiltered(Long targetId); - } diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java b/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java index 43699879..731c70cc 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendRepository.java @@ -16,6 +16,8 @@ public interface FriendRepository { Optional findByUserAndTarget(Long userId, Long targetId); + Optional findByUserAndTargetNotFiltered(Long userId, Long targetId); + Friend getByUserAndTarget(Long userId, Long targetId); boolean existsByUserAndTarget(Long userId, Long targetId); diff --git a/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java b/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java index d9db2bdc..26c79eb9 100644 --- a/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java +++ b/src/main/java/com/yello/server/domain/friend/repository/FriendRepositoryImpl.java @@ -41,6 +41,11 @@ public Optional findByUserAndTarget(Long userId, Long targetId) { return friendJpaRepository.findByUserAndTarget(userId, targetId); } + @Override + public Optional findByUserAndTargetNotFiltered(Long userId, Long targetId) { + return friendJpaRepository.findByUserAndTargetNotFiltered(userId, targetId); + } + @Override public Friend getByUserAndTarget(Long userId, Long targetId) { return friendJpaRepository.findByUserAndTarget(userId, targetId) diff --git a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java index 7406bc05..1ae56d1f 100644 --- a/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java +++ b/src/test/java/com/yello/server/small/domain/friend/FakeFriendRepository.java @@ -19,12 +19,12 @@ public class FakeFriendRepository implements FriendRepository { @Override public Friend save(Friend friend) { - if (friend.getId()!=null && friend.getId() > id) { + if (friend.getId() != null && friend.getId() > id) { id = friend.getId(); } Friend newFriend = Friend.builder() - .id(friend.getId()==null ? ++id : friend.getId()) + .id(friend.getId() == null ? ++id : friend.getId()) .user(friend.getUser()) .target(friend.getTarget()) .deletedAt(null) @@ -42,7 +42,7 @@ public void delete(Friend friend) { @Override public Integer countAllByUserId(Long userId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt()==null) + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList() .size(); } @@ -51,7 +51,14 @@ public Integer countAllByUserId(Long userId) { public Optional findByUserAndTarget(Long userId, Long targetId) { return data.stream() .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId) - && friend.getDeletedAt()==null) + && friend.getDeletedAt() == null) + .findFirst(); + } + + @Override + public Optional findByUserAndTargetNotFiltered(Long userId, Long targetId) { + return data.stream() + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId)) .findFirst(); } @@ -60,7 +67,7 @@ public Friend getByUserAndTarget(Long userId, Long targetId) { return data.stream() .filter(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId) - && friend.getDeletedAt()==null) + && friend.getDeletedAt() == null) .findFirst() .orElseThrow(() -> new FriendNotFoundException(NOT_FOUND_FRIEND_EXCEPTION)); } @@ -70,13 +77,13 @@ public boolean existsByUserAndTarget(Long userId, Long targetId) { return data.stream() .anyMatch(friend -> friend.getUser().getId().equals(userId) && friend.getTarget().getId().equals(targetId) - && friend.getDeletedAt()==null); + && friend.getDeletedAt() == null); } @Override public Page findAllFriendsByUserId(Pageable pageable, Long userId) { final List friends = data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt()==null) + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList(); final int start = (int) pageable.getOffset(); @@ -87,7 +94,7 @@ public Page findAllFriendsByUserId(Pageable pageable, Long userId) { @Override public List findAllByUserId(Long userId) { return data.stream() - .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt()==null) + .filter(friend -> friend.getUser().getId().equals(userId) && friend.getDeletedAt() == null) .toList(); } @@ -95,7 +102,7 @@ public List findAllByUserId(Long userId) { public List findAllByTargetId(Long targetId) { return data.stream() .filter( - friend -> friend.getTarget().getId().equals(targetId) && friend.getDeletedAt()==null) + friend -> friend.getTarget().getId().equals(targetId) && friend.getDeletedAt() == null) .toList(); } diff --git a/src/test/java/com/yello/server/small/domain/friend/FriendServiceTest.java b/src/test/java/com/yello/server/small/domain/friend/FriendServiceTest.java index b8c3132d..804d3b4b 100644 --- a/src/test/java/com/yello/server/small/domain/friend/FriendServiceTest.java +++ b/src/test/java/com/yello/server/small/domain/friend/FriendServiceTest.java @@ -25,6 +25,7 @@ import com.yello.server.small.domain.user.FakeUserRepository; import com.yello.server.small.domain.vote.FakeVoteRepository; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.data.domain.Pageable; @@ -232,10 +233,10 @@ void init() { // when friendService.deleteFriend(userId, targetId); - final List friends = friendRepository.findAllByUserIdNotFiltered(userId); + final Optional friends = friendRepository.findByUserAndTargetNotFiltered(userId, targetId); // then - assertThat(friends.get(0).getDeletedAt()).isNotNull(); + assertThat(friends.isEmpty()).isEqualTo(true); } @Test diff --git a/src/test/java/com/yello/server/small/domain/vote/VoteServiceTest.java b/src/test/java/com/yello/server/small/domain/vote/VoteServiceTest.java index bdb33bff..61eb99cd 100644 --- a/src/test/java/com/yello/server/small/domain/vote/VoteServiceTest.java +++ b/src/test/java/com/yello/server/small/domain/vote/VoteServiceTest.java @@ -28,11 +28,14 @@ import com.yello.server.domain.vote.entity.Vote; import com.yello.server.domain.vote.repository.VoteRepository; import com.yello.server.domain.vote.service.VoteService; +import com.yello.server.infrastructure.rabbitmq.service.ProducerService; import com.yello.server.small.domain.cooldown.FakeCooldownRepository; import com.yello.server.small.domain.friend.FakeFriendRepository; import com.yello.server.small.domain.keyword.FakeKeywordRepository; import com.yello.server.small.domain.question.FakeQuestionRepository; import com.yello.server.small.domain.user.FakeUserRepository; +import com.yello.server.small.global.rabbitmq.FakeMessageQueueRepository; +import com.yello.server.small.global.rabbitmq.FakeProducerService; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -48,6 +51,7 @@ public class VoteServiceTest { private final CooldownRepository cooldownRepository = new FakeCooldownRepository(); private final QuestionRepository questionRepository = new FakeQuestionRepository(); private final KeywordRepository keywordRepository = new FakeKeywordRepository(); + private final ProducerService producerService = new FakeProducerService(new FakeMessageQueueRepository()); private VoteService voteService; private Question question1; private Question question2; @@ -70,6 +74,7 @@ void init() { .userRepository(userRepository) .questionRepository(questionRepository) .keywordRepository(keywordRepository) + .producerService(producerService) .build(); School school = School.builder() diff --git a/src/test/java/com/yello/server/small/global/rabbitmq/FakeMessageQueueRepository.java b/src/test/java/com/yello/server/small/global/rabbitmq/FakeMessageQueueRepository.java new file mode 100644 index 00000000..742cd5a3 --- /dev/null +++ b/src/test/java/com/yello/server/small/global/rabbitmq/FakeMessageQueueRepository.java @@ -0,0 +1,13 @@ +package com.yello.server.small.global.rabbitmq; + +import com.yello.server.infrastructure.rabbitmq.repository.MessageQueueRepository; +import org.springframework.amqp.core.MessagePostProcessor; + +public class FakeMessageQueueRepository implements MessageQueueRepository { + + @Override + public void convertAndSend(String exchange, String routingKey, Object message, + MessagePostProcessor messagePostProcessor) { + + } +} diff --git a/src/test/java/com/yello/server/small/global/rabbitmq/FakeProducerService.java b/src/test/java/com/yello/server/small/global/rabbitmq/FakeProducerService.java new file mode 100644 index 00000000..0458d0d6 --- /dev/null +++ b/src/test/java/com/yello/server/small/global/rabbitmq/FakeProducerService.java @@ -0,0 +1,19 @@ +package com.yello.server.small.global.rabbitmq; + +import com.yello.server.domain.cooldown.entity.Cooldown; +import com.yello.server.infrastructure.rabbitmq.repository.MessageQueueRepository; +import com.yello.server.infrastructure.rabbitmq.service.ProducerService; + +public class FakeProducerService implements ProducerService { + + private final MessageQueueRepository messageQueueRepository; + + public FakeProducerService(MessageQueueRepository messageQueueRepository) { + this.messageQueueRepository = messageQueueRepository; + } + + @Override + public void produceVoteAvailableNotification(Cooldown cooldown) { + + } +}