Skip to content

Commit

Permalink
✨ [Feat] 차단 목록에서 특정 회원 삭제 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjin3395 committed Sep 19, 2024
1 parent eab750b commit 0c48c83
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public enum ErrorStatus implements BaseErrorCode {
ALREADY_BLOCKED(HttpStatus.BAD_REQUEST, "BLOCK402", "이미 차단한 회원입니다."),
TARGET_MEMBER_NOT_BLOCKED(HttpStatus.BAD_REQUEST, "BLOCK403", "차단 목록에 존재하지 않는 회원입니다."),
BLOCK_MEMBER_BAD_REQUEST(HttpStatus.BAD_REQUEST, "BLOCK404", "잘못된 친구 차단 요청입니다."),
DELETE_BLOCKED_MEMBER_FAILED(HttpStatus.BAD_REQUEST, "BLOCK405", "차단 목록에서 삭제 불가한 회원입니다."),

// 신고 관련 에러
REPORT_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "REPORT401", "신고 대상 회원을 찾을 수 없습니다."),
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/gamegoo/controller/member/BlockController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ApiResponse<String> blockMember(@PathVariable(name = "memberId") Long tar
@Parameter(name = "page", description = "페이지 번호, 1 이상의 숫자를 입력해 주세요.")
@GetMapping
public ApiResponse<MemberResponse.blockListDTO> getBlockList(
@RequestParam(name = "page") Integer page) {
@RequestParam(name = "page") Integer page) {
Long memberId = JWTUtil.getCurrentUserId();

Page<Member> blockList = blockService.getBlockList(memberId, page - 1);
Expand All @@ -62,4 +62,16 @@ public ApiResponse<String> unBlockMember(@PathVariable(name = "memberId") Long t
return ApiResponse.onSuccess("차단 해제 성공");
}

@Operation(summary = "차단 목록에서 해당 회원 삭제 API", description = "차단 목록에서 해당 회원을 삭제하는 API 입니다. (차단 해제 아님)")
@Parameter(name = "memberId", description = "목록에서 삭제할 대상 회원의 id 입니다.")
@DeleteMapping("/delete/{memberId}")
public ApiResponse<String> deleteBlockMember(
@PathVariable(name = "memberId") Long targetMemberId) {
Long memberId = JWTUtil.getCurrentUserId();
blockService.deleteBlockMember(memberId, targetMemberId);

return ApiResponse.onSuccess("차단 목록에서 삭제 성공");
}


}
5 changes: 5 additions & 0 deletions src/main/java/com/gamegoo/domain/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public void removeBlockerMember(Member blockerMember) {
blockerMember.getBlockList().remove(this);
this.blockerMember = null;
}

// Block 엔티티의 isDeleted를 변경하는 메소드
public void updateIsDeleted(Boolean isDeleted) {
this.isDeleted = isDeleted;
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/gamegoo/service/member/BlockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,30 @@ public void unBlockMember(Long memberId, Long targetMemberId) {
blockRepository.delete(block);
}

/**
* memberId에 해당하는 회원이 targetMemberId에 해당하는 회원을 자신의 차단 목록에서 삭제 처리 =
*
* @param memberId
* @param targetMemberId
*/
public void deleteBlockMember(Long memberId, Long targetMemberId) {
// member 엔티티 조회
Member member = profileService.findMember(memberId);
Member targetMember = profileService.findMember(targetMemberId);

// targetMember가 차단 실제로 차단 목록에 존재하는지 검증
Block block = blockRepository.findByBlockerMemberAndBlockedMember(member, targetMember)
.orElseThrow(() -> new BlockHandler(ErrorStatus.TARGET_MEMBER_NOT_BLOCKED));

// targetMember가 탈퇴한 회원이 맞는지 검증
if (!targetMember.getBlind()) {
throw new BlockHandler(ErrorStatus.DELETE_BLOCKED_MEMBER_FAILED);
}

// Block 엔티티의 isDeleted 업데이트
block.updateIsDeleted(true);

}


}

0 comments on commit 0c48c83

Please sign in to comment.