Skip to content

Commit

Permalink
feat: 리뷰 삭제시 멤버 레벨 재조정 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
EunjiShin authored Aug 3, 2024
1 parent 337d160 commit cfa4000
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ MyReviewListResult findMyReviewsByUserId(

long countByIdByMemberId(Long memberId);

long countByMember(Long memberId);

@Builder
record BlockReviewListResult(
LocationInfo location,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.depromeet.spot.domain.seat.Seat;
import org.depromeet.spot.usecase.port.in.member.UpdateMemberUsecase;
import org.depromeet.spot.usecase.port.in.review.CreateReviewUsecase;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
import org.depromeet.spot.usecase.port.out.member.MemberRepository;
import org.depromeet.spot.usecase.port.out.review.BlockTopKeywordRepository;
import org.depromeet.spot.usecase.port.out.review.KeywordRepository;
Expand All @@ -34,6 +35,7 @@ public class CreateReviewService implements CreateReviewUsecase {
private final KeywordRepository keywordRepository;
private final BlockTopKeywordRepository blockTopKeywordRepository;
private final UpdateMemberUsecase updateMemberUsecase;
private final ReadReviewUsecase readReviewUsecase;

@Override
@Transactional
Expand Down Expand Up @@ -78,7 +80,7 @@ private Review convertToDomain(Seat seat, Member member, CreateReviewCommand com
}

public Member calculateMemberLevel(final Member member) {
final long memberReviewCnt = reviewRepository.countByUserId(member.getId());
final long memberReviewCnt = readReviewUsecase.countByMember(member.getId());
return updateMemberUsecase.updateLevel(member, memberReviewCnt);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.depromeet.spot.usecase.service.review;

import org.depromeet.spot.domain.member.Member;
import org.depromeet.spot.usecase.port.in.member.ReadMemberUsecase;
import org.depromeet.spot.usecase.port.in.member.UpdateMemberUsecase;
import org.depromeet.spot.usecase.port.in.review.DeleteReviewUsecase;
import org.depromeet.spot.usecase.port.in.review.ReadReviewUsecase;
import org.depromeet.spot.usecase.port.out.review.ReviewRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -12,10 +16,21 @@
public class DeleteReviewService implements DeleteReviewUsecase {

private final ReviewRepository reviewRepository;
private final ReadReviewUsecase readReviewUsecase;
private final UpdateMemberUsecase updateMemberUsecase;
private final ReadMemberUsecase readMemberUsecase;

@Override
@Transactional
public Long deleteReview(Long reviewId, Long memberId) {
return reviewRepository.softDeleteByIdAndMemberId(reviewId, memberId);
Long deletedReviewId = reviewRepository.softDeleteByIdAndMemberId(reviewId, memberId);
updateMemberLevel(memberId);
return deletedReviewId;
}

public void updateMemberLevel(Long memberId) {
Member member = readMemberUsecase.findById(memberId);
long reviewCnt = readReviewUsecase.countByMember(memberId);
updateMemberUsecase.updateLevel(member, reviewCnt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ public long countByIdByMemberId(Long memberId) {
return reviewRepository.countByIdByMemberId(memberId);
}

@Override
public long countByMember(Long memberId) {
return reviewRepository.countByUserId(memberId);
}

@Override
public MyRecentReviewResult findLastReviewByMemberId(Long memberId) {
Review review = reviewRepository.findLastReviewByMemberId(memberId);
Expand Down

0 comments on commit cfa4000

Please sign in to comment.