Skip to content

Commit

Permalink
feat: 내 팔로워 목록 중 선택한 유저 내 팔로워에서 지우기 (#287)
Browse files Browse the repository at this point in the history
* feat: 내 팔로워 목록 중 선택한 유저 내 팔로워에서 지우기

* test: 팔로워 삭제 테스트코드 작성

* fix: @uwoobeat 코드리뷰 수정
  • Loading branch information
kdomo authored Feb 7, 2024
1 parent 0fe3634 commit 09a6966
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
import com.depromeet.domain.follow.application.FollowService;
import com.depromeet.domain.follow.dto.request.FollowCreateRequest;
import com.depromeet.domain.follow.dto.request.FollowDeleteRequest;
import com.depromeet.domain.follow.dto.response.FollowFindMeInfoResponse;
import com.depromeet.domain.follow.dto.response.FollowFindTargetInfoResponse;
import com.depromeet.domain.follow.dto.response.FollowListResponse;
import com.depromeet.domain.follow.dto.response.MemberFollowedResponse;
import com.depromeet.domain.follow.dto.response.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -63,4 +60,10 @@ public List<MemberFollowedResponse> followedUserFindAll() {
public FollowListResponse followList(@PathVariable Long targetId) {
return followService.findFollowList(targetId);
}

@DeleteMapping({"/{targetId}"})
@Operation(summary = "팔로워 삭제", description = "내 팔로워 목록 중 targetId로 팔로워를 삭제합니다.")
public ResponseEntity<FollowerDeletedResponse> followerDelete(@PathVariable Long targetId) {
return ResponseEntity.ok(followService.deleteFollower(targetId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,24 @@ public FollowListResponse findFollowList(Long targetId) {
targetMember.getProfile().getNickname(), followingList, followerList);
}

public FollowerDeletedResponse deleteFollower(Long targetId) {
final Member currentMember = memberUtil.getCurrentMember();
final Member targetMember = getTargetMember(targetId);

MemberRelation memberRelation =
memberRelationRepository
.findBySourceIdAndTargetId(targetMember.getId(), currentMember.getId())
.orElseThrow(() -> new CustomException(ErrorCode.FOLLOW_NOT_EXIST));
memberRelationRepository.delete(memberRelation);

Optional<MemberRelation> optionalMemberRelation =
memberRelationRepository.findBySourceIdAndTargetId(
currentMember.getId(), targetMember.getId());
return optionalMemberRelation.isPresent()
? FollowerDeletedResponse.from(FollowStatus.FOLLOWING)
: FollowerDeletedResponse.from(FollowStatus.NOT_FOLLOWING);
}

private static void getFollowStatusIncludeList(
List<Member> targetMembers,
List<MemberRelation> currentMemberSources,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.depromeet.domain.follow.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;

public record FollowerDeletedResponse(
@Schema(description = "팔로워 삭제 후 나와 target과의 팔로우 상태", defaultValue = "NOT_FOLLOWING")
FollowStatus followStatus) {
public static FollowerDeletedResponse from(FollowStatus followStatus) {
return new FollowerDeletedResponse(followStatus);
}
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import com.depromeet.domain.follow.domain.MemberRelation;
import com.depromeet.domain.follow.dto.request.FollowCreateRequest;
import com.depromeet.domain.follow.dto.request.FollowDeleteRequest;
import com.depromeet.domain.follow.dto.response.FollowFindMeInfoResponse;
import com.depromeet.domain.follow.dto.response.FollowFindTargetInfoResponse;
import com.depromeet.domain.follow.dto.response.FollowStatus;
import com.depromeet.domain.follow.dto.response.MemberFollowedResponse;
import com.depromeet.domain.follow.dto.response.*;
import com.depromeet.domain.member.dao.MemberRepository;
import com.depromeet.domain.member.domain.Member;
import com.depromeet.domain.member.domain.Profile;
Expand Down Expand Up @@ -496,4 +493,90 @@ class 내가_팔로우한_유저_정보_리스트를_조회할_때 {
assertEquals("targetMember2", response.get(1).nickname());
}
}

@Nested
class 나의_팔로워를_삭제할_때 {
@Test
void 로그인된_회원이_존재하지_않는다면_예외를_발생시킨다() {
// when, then
assertThatThrownBy(() -> followService.deleteFollower(224L))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage());
}

@Test
void 삭제하려는_회원이_존재하지_않는다면_예외를_발생시킨다() {
// given
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("currentMember", "currentMember")));

// when, then
assertThatThrownBy(() -> followService.deleteFollower(224L))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.FOLLOW_TARGET_MEMBER_NOT_FOUND.getMessage());
}

@Test
void 삭제하려는_유저가_나의_팔로워가_아니라면_예외가_발생한다() {
// given
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("currentMember", "currentMember")));
Member targetMember1 =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("targetMember1", "targetMember1")));
// when, then
assertThatThrownBy(() -> followService.deleteFollower(targetMember1.getId()))
.isInstanceOf(CustomException.class)
.hasMessage(ErrorCode.FOLLOW_NOT_EXIST.getMessage());
}

@Test
void 내가_팔로우_하고_있다면_FOLLOWER_STATUS가_FOLLOWING로_응답한다() {
// given
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("currentMember", "currentMember")));
Member targetMember1 =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("targetMember1", "targetMember1")));
memberRelationRepository.save(
MemberRelation.createMemberRelation(targetMember1, currentMember));
memberRelationRepository.save(
MemberRelation.createMemberRelation(currentMember, targetMember1));

// when
FollowerDeletedResponse response = followService.deleteFollower(targetMember1.getId());

// then
assertEquals(FollowStatus.FOLLOWING, response.followStatus());
}

@Test
void 내가_팔로우_하고_있지_않다면_FOLLOWER_STATUS가_NOT_FOLLOWING로_응답한다() {
// given
Member currentMember =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("currentMember", "currentMember")));
Member targetMember1 =
memberRepository.save(
Member.createNormalMember(
Profile.createProfile("targetMember1", "targetMember1")));
memberRelationRepository.save(
MemberRelation.createMemberRelation(targetMember1, currentMember));

// when
FollowerDeletedResponse response = followService.deleteFollower(targetMember1.getId());

// then
assertEquals(FollowStatus.NOT_FOLLOWING, response.followStatus());
}
}
}

0 comments on commit 09a6966

Please sign in to comment.