From 42559665471fb249b96044da8aeb7964265723b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EB=AA=A8?= Date: Fri, 9 Feb 2024 16:18:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=8C=94=EB=A1=9C=EC=9A=B0=20=EC=B7=A8?= =?UTF-8?q?=EC=86=8C=20=EC=8B=9C=20=EC=83=81=EB=8C=80=EC=9D=98=20=ED=8C=94?= =?UTF-8?q?=EB=A1=9C=EC=9A=B0=20=EC=83=81=ED=83=9C=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD=20(#296)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 팔로우 취소 시 상대의 팔로우 상태 응답 하도록 변경 * test: 팔로우 취소 시 follow Status 테스트 코드 추가 --- .../domain/follow/api/FollowController.java | 5 +- .../follow/application/FollowService.java | 10 +++- .../follow/application/FollowServiceTest.java | 49 +++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/depromeet/domain/follow/api/FollowController.java b/src/main/java/com/depromeet/domain/follow/api/FollowController.java index b85fe03bf..89818a70a 100644 --- a/src/main/java/com/depromeet/domain/follow/api/FollowController.java +++ b/src/main/java/com/depromeet/domain/follow/api/FollowController.java @@ -29,8 +29,9 @@ public ResponseEntity followCreate(@Valid @RequestBody FollowCreateRequest @DeleteMapping @Operation(summary = "팔로우 취소", description = "팔로우를 취소합니다.") - public void followDelete(@Valid @RequestBody FollowDeleteRequest request) { - followService.deleteFollow(request); + public ResponseEntity followDelete( + @Valid @RequestBody FollowDeleteRequest request) { + return ResponseEntity.ok(followService.deleteFollow(request)); } @GetMapping("/{targetId}") diff --git a/src/main/java/com/depromeet/domain/follow/application/FollowService.java b/src/main/java/com/depromeet/domain/follow/application/FollowService.java index 34c488f91..6278b5fca 100644 --- a/src/main/java/com/depromeet/domain/follow/application/FollowService.java +++ b/src/main/java/com/depromeet/domain/follow/application/FollowService.java @@ -62,7 +62,7 @@ public void createFollow(FollowCreateRequest request) { memberRelationRepository.save(memberRelation); } - public void deleteFollow(FollowDeleteRequest request) { + public FollowerDeletedResponse deleteFollow(FollowDeleteRequest request) { final Member currentMember = memberUtil.getCurrentMember(); Member targetMember = getTargetMember(request.targetId()); @@ -79,6 +79,14 @@ public void deleteFollow(FollowDeleteRequest request) { notificationRepository.delete(notification); } memberRelationRepository.delete(memberRelation); + + Optional optionalMemberRelation = + memberRelationRepository.findBySourceIdAndTargetId( + targetMember.getId(), currentMember.getId()); + + return optionalMemberRelation.isPresent() + ? FollowerDeletedResponse.from(FollowStatus.FOLLOWED_BY_ME) + : FollowerDeletedResponse.from(FollowStatus.NOT_FOLLOWING); } @Transactional(readOnly = true) diff --git a/src/test/java/com/depromeet/domain/follow/application/FollowServiceTest.java b/src/test/java/com/depromeet/domain/follow/application/FollowServiceTest.java index f5a05bafa..c64bbb0df 100644 --- a/src/test/java/com/depromeet/domain/follow/application/FollowServiceTest.java +++ b/src/test/java/com/depromeet/domain/follow/application/FollowServiceTest.java @@ -177,6 +177,55 @@ class 팔로우를_취소할_때 { .hasMessage(ErrorCode.FOLLOW_NOT_EXIST.getMessage()); } + @Test + void 상대가_나를_팔로우_하고_있다면_FOLLOW_STATUE가_FOLLOWED_BY_ME로_응답한다() { + Long targetId = 2L; + FollowDeleteRequest request = new FollowDeleteRequest(targetId); + Member currentMember = + memberRepository.save( + Member.createNormalMember( + Profile.createProfile("testNickname1", "testImageUrl1"))); + Member targetMember = + memberRepository.save( + Member.createNormalMember( + Profile.createProfile("testNickname2", "testImageUrl2"))); + MemberRelation memberRelation = + MemberRelation.createMemberRelation(currentMember, targetMember); + MemberRelation memberRelation2 = + MemberRelation.createMemberRelation(targetMember, currentMember); + memberRelationRepository.save(memberRelation); + memberRelationRepository.save(memberRelation2); + + // when + FollowerDeletedResponse response = followService.deleteFollow(request); + + // then + assertEquals(FollowStatus.FOLLOWED_BY_ME, response.followStatus()); + } + + @Test + void 상대가_나를_팔로우_하고_있지_않다면_FOLLOW_STATUE가_NOT_FOLLOWING로_응답한다() { + Long targetId = 2L; + FollowDeleteRequest request = new FollowDeleteRequest(targetId); + Member currentMember = + memberRepository.save( + Member.createNormalMember( + Profile.createProfile("testNickname1", "testImageUrl1"))); + Member targetMember = + memberRepository.save( + Member.createNormalMember( + Profile.createProfile("testNickname2", "testImageUrl2"))); + MemberRelation memberRelation = + MemberRelation.createMemberRelation(currentMember, targetMember); + memberRelationRepository.save(memberRelation); + + // when + FollowerDeletedResponse response = followService.deleteFollow(request); + + // then + assertEquals(FollowStatus.NOT_FOLLOWING, response.followStatus()); + } + @Test void 정상적이라면_팔로우가_취소된다() { Long targetId = 2L;