Skip to content

Commit

Permalink
feat: 팔로우 취소 시 상대의 팔로우 상태 응답하도록 변경 (#296)
Browse files Browse the repository at this point in the history
* feat: 팔로우 취소 시 상대의 팔로우 상태 응답 하도록 변경

* test: 팔로우 취소 시 follow Status 테스트 코드 추가
  • Loading branch information
kdomo authored Feb 9, 2024
1 parent 0eff937 commit 4255966
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public ResponseEntity<Void> followCreate(@Valid @RequestBody FollowCreateRequest

@DeleteMapping
@Operation(summary = "팔로우 취소", description = "팔로우를 취소합니다.")
public void followDelete(@Valid @RequestBody FollowDeleteRequest request) {
followService.deleteFollow(request);
public ResponseEntity<FollowerDeletedResponse> followDelete(
@Valid @RequestBody FollowDeleteRequest request) {
return ResponseEntity.ok(followService.deleteFollow(request));
}

@GetMapping("/{targetId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -79,6 +79,14 @@ public void deleteFollow(FollowDeleteRequest request) {
notificationRepository.delete(notification);
}
memberRelationRepository.delete(memberRelation);

Optional<MemberRelation> optionalMemberRelation =
memberRelationRepository.findBySourceIdAndTargetId(
targetMember.getId(), currentMember.getId());

return optionalMemberRelation.isPresent()
? FollowerDeletedResponse.from(FollowStatus.FOLLOWED_BY_ME)
: FollowerDeletedResponse.from(FollowStatus.NOT_FOLLOWING);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4255966

Please sign in to comment.