Skip to content

Commit

Permalink
Merge pull request #224 from Gamegoo-repo/feat/217
Browse files Browse the repository at this point in the history
[Feat/217] 차단 목록 삭제 기능 구현
  • Loading branch information
Eunjin3395 authored Sep 20, 2024
2 parents d331242 + 0c48c83 commit 2b28cb0
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/main/generated/com/gamegoo/domain/QBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class QBlock extends EntityPathBase<Block> {

public final NumberPath<Long> id = createNumber("id", Long.class);

public final BooleanPath isDeleted = createBoolean("isDeleted");

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

Expand Down
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("차단 목록에서 삭제 성공");
}


}
28 changes: 24 additions & 4 deletions src/main/java/com/gamegoo/domain/Block.java
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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;
Expand All @@ -41,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;
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
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<Member, Long> {

Optional<Member> findByEmail(String email);

Optional<Member> findById(Long id);

Optional<Member> 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<Member> 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<Member> findBlockedMembersByBlockerIdAndNotDeleted(@Param("blockerId") Long blockerId,
Pageable pageable);

List<Member> findAllByIdBetween(Long startId, Long endId);

Expand Down
28 changes: 27 additions & 1 deletion src/main/java/com/gamegoo/service/member/BlockService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public Member blockMember(Long memberId, Long targetMemberId) {

// block 엔티티 생성 및 연관관계 매핑
Block block = Block.builder()
.isDeleted(false)
.blockedMember(targetMember)
.build();
block.setBlockerMember(member);
Expand Down Expand Up @@ -100,7 +101,7 @@ public Page<Member> getBlockList(Long memberId, Integer pageIdx) {

PageRequest pageRequest = PageRequest.of(pageIdx, PAGE_SIZE);

return memberRepository.findBlockedMembersByBlockerIdAndNotBlind(member.getId(),
return memberRepository.findBlockedMembersByBlockerIdAndNotDeleted(member.getId(),
pageRequest);
}

Expand All @@ -123,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 2b28cb0

Please sign in to comment.