From 0c48c83916ebd6a17c206cb9fd7f52f10a3adaf4 Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Thu, 19 Sep 2024 23:48:44 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20[Feat]=20=EC=B0=A8=EB=8B=A8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=EC=97=90=EC=84=9C=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=20=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiPayload/code/status/ErrorStatus.java | 1 + .../controller/member/BlockController.java | 14 ++++++++++- src/main/java/com/gamegoo/domain/Block.java | 5 ++++ .../gamegoo/service/member/BlockService.java | 25 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java b/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java index aa2bb44c..0062b8c7 100644 --- a/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/com/gamegoo/apiPayload/code/status/ErrorStatus.java @@ -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", "신고 대상 회원을 찾을 수 없습니다."), diff --git a/src/main/java/com/gamegoo/controller/member/BlockController.java b/src/main/java/com/gamegoo/controller/member/BlockController.java index 47ba8df4..a7e94dc0 100644 --- a/src/main/java/com/gamegoo/controller/member/BlockController.java +++ b/src/main/java/com/gamegoo/controller/member/BlockController.java @@ -44,7 +44,7 @@ public ApiResponse blockMember(@PathVariable(name = "memberId") Long tar @Parameter(name = "page", description = "페이지 번호, 1 이상의 숫자를 입력해 주세요.") @GetMapping public ApiResponse getBlockList( - @RequestParam(name = "page") Integer page) { + @RequestParam(name = "page") Integer page) { Long memberId = JWTUtil.getCurrentUserId(); Page blockList = blockService.getBlockList(memberId, page - 1); @@ -62,4 +62,16 @@ public ApiResponse unBlockMember(@PathVariable(name = "memberId") Long t return ApiResponse.onSuccess("차단 해제 성공"); } + @Operation(summary = "차단 목록에서 해당 회원 삭제 API", description = "차단 목록에서 해당 회원을 삭제하는 API 입니다. (차단 해제 아님)") + @Parameter(name = "memberId", description = "목록에서 삭제할 대상 회원의 id 입니다.") + @DeleteMapping("/delete/{memberId}") + public ApiResponse deleteBlockMember( + @PathVariable(name = "memberId") Long targetMemberId) { + Long memberId = JWTUtil.getCurrentUserId(); + blockService.deleteBlockMember(memberId, targetMemberId); + + return ApiResponse.onSuccess("차단 목록에서 삭제 성공"); + } + + } diff --git a/src/main/java/com/gamegoo/domain/Block.java b/src/main/java/com/gamegoo/domain/Block.java index 85cae4e0..d29a63e6 100644 --- a/src/main/java/com/gamegoo/domain/Block.java +++ b/src/main/java/com/gamegoo/domain/Block.java @@ -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; + } } diff --git a/src/main/java/com/gamegoo/service/member/BlockService.java b/src/main/java/com/gamegoo/service/member/BlockService.java index 110a54b6..88769766 100644 --- a/src/main/java/com/gamegoo/service/member/BlockService.java +++ b/src/main/java/com/gamegoo/service/member/BlockService.java @@ -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); + + } + }