From eab750b6694c05c539cc468074e6dcd15485d518 Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Thu, 19 Sep 2024 23:24:54 +0900 Subject: [PATCH 1/2] =?UTF-8?q?:sparkles:=20[Feat]=20Block=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=EC=97=90=20isDeleted=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generated/com/gamegoo/domain/QBlock.java | 2 ++ src/main/java/com/gamegoo/domain/Block.java | 23 +++++++++++++++---- .../repository/member/MemberRepository.java | 11 +++++---- .../gamegoo/service/member/BlockService.java | 3 ++- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/generated/com/gamegoo/domain/QBlock.java b/src/main/generated/com/gamegoo/domain/QBlock.java index b616420d..2440a7f2 100644 --- a/src/main/generated/com/gamegoo/domain/QBlock.java +++ b/src/main/generated/com/gamegoo/domain/QBlock.java @@ -33,6 +33,8 @@ public class QBlock extends EntityPathBase { public final NumberPath id = createNumber("id", Long.class); + public final BooleanPath isDeleted = createBoolean("isDeleted"); + //inherited public final DateTimePath updatedAt = _super.updatedAt; diff --git a/src/main/java/com/gamegoo/domain/Block.java b/src/main/java/com/gamegoo/domain/Block.java index b93c85a9..85cae4e0 100644 --- a/src/main/java/com/gamegoo/domain/Block.java +++ b/src/main/java/com/gamegoo/domain/Block.java @@ -1,10 +1,21 @@ package com.gamegoo.domain; -import com.gamegoo.domain.member.Member; import com.gamegoo.domain.common.BaseDateTimeEntity; -import lombok.*; - -import javax.persistence.*; +import com.gamegoo.domain.member.Member; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; @Entity @Table(name = "Block") @@ -13,11 +24,15 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor public class Block extends BaseDateTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "block_id") private Long id; + @Column(nullable = false) + private Boolean isDeleted; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "blocker_id", nullable = false) private Member blockerMember; diff --git a/src/main/java/com/gamegoo/repository/member/MemberRepository.java b/src/main/java/com/gamegoo/repository/member/MemberRepository.java index 9f38ced6..96a79bc3 100644 --- a/src/main/java/com/gamegoo/repository/member/MemberRepository.java +++ b/src/main/java/com/gamegoo/repository/member/MemberRepository.java @@ -1,16 +1,16 @@ package com.gamegoo.repository.member; import com.gamegoo.domain.member.Member; +import java.util.List; +import java.util.Optional; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import java.util.List; -import java.util.Optional; - public interface MemberRepository extends JpaRepository { + Optional findByEmail(String email); Optional findByGameName(String gameName); @@ -19,8 +19,9 @@ public interface MemberRepository extends JpaRepository { Optional findByRefreshToken(String refresh_token); - @Query("SELECT m FROM Member m INNER JOIN Block b ON m.id = b.blockedMember.id WHERE b.blockerMember.id = :blockerId AND m.blind = false ORDER BY b.createdAt DESC") - Page findBlockedMembersByBlockerIdAndNotBlind(@Param("blockerId") Long blockerId, Pageable pageable); + @Query("SELECT m FROM Member m INNER JOIN Block b ON m.id = b.blockedMember.id WHERE b.blockerMember.id = :blockerId AND b.isDeleted = false ORDER BY b.createdAt DESC") + Page findBlockedMembersByBlockerIdAndNotDeleted(@Param("blockerId") Long blockerId, + Pageable pageable); List findAllByIdBetween(Long startId, Long endId); diff --git a/src/main/java/com/gamegoo/service/member/BlockService.java b/src/main/java/com/gamegoo/service/member/BlockService.java index 5170771e..110a54b6 100644 --- a/src/main/java/com/gamegoo/service/member/BlockService.java +++ b/src/main/java/com/gamegoo/service/member/BlockService.java @@ -60,6 +60,7 @@ public Member blockMember(Long memberId, Long targetMemberId) { // block 엔티티 생성 및 연관관계 매핑 Block block = Block.builder() + .isDeleted(false) .blockedMember(targetMember) .build(); block.setBlockerMember(member); @@ -100,7 +101,7 @@ public Page getBlockList(Long memberId, Integer pageIdx) { PageRequest pageRequest = PageRequest.of(pageIdx, PAGE_SIZE); - return memberRepository.findBlockedMembersByBlockerIdAndNotBlind(member.getId(), + return memberRepository.findBlockedMembersByBlockerIdAndNotDeleted(member.getId(), pageRequest); } From 0c48c83916ebd6a17c206cb9fd7f52f10a3adaf4 Mon Sep 17 00:00:00 2001 From: Eunjin3395 Date: Thu, 19 Sep 2024 23:48:44 +0900 Subject: [PATCH 2/2] =?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); + + } + }