Skip to content

Commit

Permalink
[BSVR-254] 탈퇴 시 리뷰 삭제 구현 (#190)
Browse files Browse the repository at this point in the history
* feat : 회원 탈퇴 시 리뷰 삭제 구현

* refactor : jwtToken 생성 prod에서 제외
  • Loading branch information
wjdwnsdnjs13 authored Sep 11, 2024
1 parent 9f10e52 commit 78b256a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.depromeet.spot.application.member.dto.response.JwtTokenResponse;
import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.domain.member.enums.MemberRole;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,6 +20,7 @@
@Slf4j
@Tag(name = "Jwt 생성용")
@RequestMapping("/api/v1/jwts")
@Profile("!prod")
public class JwtCreateController {

private final JwtTokenUtil jwtTokenUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ int softDeleteByIdAndMemberId(
@Param("memberId") Long memberId,
@Param("deletedAt") LocalDateTime deletedAt);

@Modifying
@Query(
"UPDATE ReviewEntity r SET r.deletedAt = :deletedAt WHERE r.member.id = :memberId AND r.deletedAt IS NULL")
void softDeleteAllReviewOwnedByMemberId(
@Param("memberId") Long memberId, @Param("deletedAt") LocalDateTime deletedAt);

@Query(
"SELECT r FROM ReviewEntity r WHERE r.member.id = :memberId "
+ "AND r.deletedAt IS NULL "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ public Long softDeleteByIdAndMemberId(Long reviewId, Long memberId) {
return reviewId;
}

@Override
public void softDeleteAllReviewOwnedByMemberId(Long memberId) {
reviewJpaRepository.softDeleteAllReviewOwnedByMemberId(memberId, LocalDateTime.now());
}

@Override
public LocationInfo findLocationInfoByStadiumIdAndBlockCode(Long stadiumId, String blockCode) {
return reviewCustomRepository.findLocationInfoByStadiumIdAndBlockCode(stadiumId, blockCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public interface DeleteReviewUsecase {

Long deleteReview(Long reviewId, Long memberId);

void deleteAllReviewOwnedByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ List<Review> findAllByUserId(

Long softDeleteByIdAndMemberId(Long reviewId, Long memberId);

void softDeleteAllReviewOwnedByMemberId(Long memberId);

LocationInfo findLocationInfoByStadiumIdAndBlockCode(Long stadiumId, String blockCode);

Review findLastReviewByMemberId(Long memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.depromeet.spot.usecase.port.in.member.MemberUsecase;
import org.depromeet.spot.usecase.port.in.member.ReadMemberUsecase;
import org.depromeet.spot.usecase.port.in.member.level.ReadLevelUsecase;
import org.depromeet.spot.usecase.port.in.review.DeleteReviewUsecase;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
import org.depromeet.spot.usecase.port.in.team.ReadBaseballTeamUsecase;
import org.depromeet.spot.usecase.port.out.member.MemberRepository;
Expand All @@ -32,6 +33,7 @@ public class MemberService implements MemberUsecase {
private final ReadMemberUsecase readMemberUsecase;
private final ReadLevelUsecase readLevelUsecase;
private final ReadBaseballTeamUsecase readBaseballTeamUsecase;
private final DeleteReviewUsecase deleteReviewUsecase;

private final ReadReviewUsecase readReviewUsecase;

Expand Down Expand Up @@ -106,8 +108,13 @@ public MemberInfo findMemberInfo(Long memberId) {
return MemberInfo.of(member, baseballTeam, reviewCntToLevelUp);
}

@Transactional
@Override
public void softDelete(Long memberId) {

// 멤버 삭제 전 리뷰 삭제가 우선이 되어야함!
deleteReviewUsecase.deleteAllReviewOwnedByMemberId(memberId);

memberRepository.updateDeletedAt(memberId, LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public Long deleteReview(Long reviewId, Long memberId) {
return deletedReviewId;
}

@Override
public void deleteAllReviewOwnedByMemberId(Long memberId) {
reviewRepository.softDeleteAllReviewOwnedByMemberId(memberId);
}

public void updateMemberLevel(Long memberId) {
Member member = readMemberUsecase.findById(memberId);
long reviewCnt = readReviewUsecase.countByMember(memberId);
Expand Down

0 comments on commit 78b256a

Please sign in to comment.