From cc50cc4933a1943e756089cdd54e1f1cd62c3c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=9A=A9=EC=88=98?= Date: Thu, 19 Sep 2024 00:32:51 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EB=A6=AC=EB=B7=B0=20SQL=EB=AC=B8=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/controller/ReviewController.java | 2 +- .../entity/dto/ReviewStatusRequest.java | 4 ++++ .../review/repository/ReviewRepository.java | 10 +++++----- .../domain/review/service/ReviewService.java | 19 ++++++++----------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/backend/src/main/java/com/worlabel/domain/review/controller/ReviewController.java b/backend/src/main/java/com/worlabel/domain/review/controller/ReviewController.java index 29ea575..f667ce5 100644 --- a/backend/src/main/java/com/worlabel/domain/review/controller/ReviewController.java +++ b/backend/src/main/java/com/worlabel/domain/review/controller/ReviewController.java @@ -45,7 +45,7 @@ public class ReviewController { public List getReviewByProject( @CurrentUser final Integer memberId, @PathVariable("project_id") final Integer projectId, - @Parameter(name = "리뷰 상태", description = "리뷰 상태", example = "APPROVED") @RequestParam(value = "reviewStatus", required = false) final ReviewStatusRequest reviewStatusRequest, + @Parameter(name = "리뷰 상태", description = "리뷰 상태", example = "APPROVED") @RequestParam(value = "reviewStatus", required = false) final String reviewStatusRequest, @Parameter(name = "마지막 리뷰 id", description = "마지막 리뷰 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastReviewId, @Parameter(name = "가져올 리뷰 수", description = "가져올 리뷰 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) { return reviewService.getReviewByProjectId(memberId, projectId, reviewStatusRequest, lastReviewId, limitPage); diff --git a/backend/src/main/java/com/worlabel/domain/review/entity/dto/ReviewStatusRequest.java b/backend/src/main/java/com/worlabel/domain/review/entity/dto/ReviewStatusRequest.java index a50ff96..15c8745 100644 --- a/backend/src/main/java/com/worlabel/domain/review/entity/dto/ReviewStatusRequest.java +++ b/backend/src/main/java/com/worlabel/domain/review/entity/dto/ReviewStatusRequest.java @@ -16,4 +16,8 @@ public class ReviewStatusRequest { @Schema(description = "리뷰 상태", example = "거부") @NotNull(message = "상태를 입력하세요.") private ReviewStatus reviewStatus; + + public static ReviewStatusRequest of(String status){ + return new ReviewStatusRequest(ReviewStatus.valueOf(status)); + } } diff --git a/backend/src/main/java/com/worlabel/domain/review/repository/ReviewRepository.java b/backend/src/main/java/com/worlabel/domain/review/repository/ReviewRepository.java index 85efe72..fc6d7de 100644 --- a/backend/src/main/java/com/worlabel/domain/review/repository/ReviewRepository.java +++ b/backend/src/main/java/com/worlabel/domain/review/repository/ReviewRepository.java @@ -18,13 +18,13 @@ public interface ReviewRepository extends JpaRepository { Optional findByIdAndMemberId(Integer reviewId, Integer memberId); - @Query(value = "SELECT r.*, m.* " + - "FROM review r JOIN member m ON r.member_id = m.member_id " + - "WHERE r.project_id = :projectId AND (:reviewStatus IS NULL OR r.status = :reviewStatus) AND (:lastReviewId IS NULL OR r.review_id < :lastReviewId) " + - "ORDER BY r.review_id DESC LIMIT :limit", nativeQuery = true) + @Query("SELECT r, m " + + "FROM Review r JOIN Member m ON r.id = m.id " + + "WHERE r.project.id = :projectId AND (:reviewStatus IS NULL OR r.reviewStatus = :reviewStatus) AND (:lastReviewId IS NULL OR r.id < :lastReviewId) " + + "ORDER BY r.id DESC LIMIT :limit") List findReviewsNativeWithLimit( @Param("projectId") Integer projectId, - @Param("reviewStatus") String reviewStatus, + @Param("reviewStatus") ReviewStatus reviewStatus, @Param("lastReviewId") Integer lastReviewId, @Param("limit") Integer limit ); diff --git a/backend/src/main/java/com/worlabel/domain/review/service/ReviewService.java b/backend/src/main/java/com/worlabel/domain/review/service/ReviewService.java index b9bcd64..7125dbf 100644 --- a/backend/src/main/java/com/worlabel/domain/review/service/ReviewService.java +++ b/backend/src/main/java/com/worlabel/domain/review/service/ReviewService.java @@ -5,6 +5,7 @@ import com.worlabel.domain.image.entity.dto.ImageResponse; import com.worlabel.domain.image.repository.ImageRepository; import com.worlabel.domain.member.entity.Member; import com.worlabel.domain.member.repository.MemberRepository; +import com.worlabel.domain.participant.entity.PrivilegeType; import com.worlabel.domain.participant.service.ParticipantService; import com.worlabel.domain.project.entity.Project; import com.worlabel.domain.project.repository.ProjectRepository; @@ -17,6 +18,7 @@ import com.worlabel.domain.review.entity.dto.ReviewResponse; import com.worlabel.domain.review.entity.dto.ReviewStatusRequest; import com.worlabel.domain.review.repository.ReviewImageRepository; import com.worlabel.domain.review.repository.ReviewRepository; +import com.worlabel.global.annotation.CheckPrivilege; import com.worlabel.global.exception.CustomException; import com.worlabel.global.exception.ErrorCode; import lombok.RequiredArgsConstructor; @@ -40,10 +42,8 @@ public class ReviewService { private final ProjectRepository projectRepository; private final ParticipantService participantService; + @CheckPrivilege(PrivilegeType.EDITOR) public ReviewResponse createReview(final Integer memberId, final Integer projectId, final ReviewRequest reviewRequest) { - // 권한 체크 편집자 이상만 리뷰 신청 가능 - participantService.checkEditorUnauthorized(memberId, projectId); - Project project = getProject(projectId); Member member = getMember(memberId); @@ -69,13 +69,12 @@ public class ReviewService { } @Transactional(readOnly = true) - public List getReviewByProjectId(final Integer memberId, final Integer projectId, final ReviewStatusRequest reviewStatusRequest, final Integer lastReviewId, final Integer limitPage) { - participantService.checkViewerUnauthorized(memberId, projectId); - + @CheckPrivilege(PrivilegeType.VIEWER) + public List getReviewByProjectId(final Integer memberId, final Integer projectId, final String reviewStatusRequest, final Integer lastReviewId, final Integer limitPage) { // 리뷰 조회 쿼리 호출 List reviews = reviewRepository.findReviewsNativeWithLimit( projectId, - reviewStatusRequest != null ? reviewStatusRequest.getReviewStatus().toValue() : null, + reviewStatusRequest == null ? null : ReviewStatus.valueOf(reviewStatusRequest), lastReviewId, limitPage ); @@ -88,9 +87,8 @@ public class ReviewService { @Transactional(readOnly = true) + @CheckPrivilege(PrivilegeType.VIEWER) public ReviewDetailResponse getReviewById(final Integer memberId, final Integer projectId, final Integer reviewId) { - participantService.checkViewerUnauthorized(memberId, projectId); - Review review = getReview(reviewId); List images = reviewImageRepository.findAllByReviewIdWithImage(reviewId).stream() @@ -118,9 +116,8 @@ public class ReviewService { } // 상태 변경 + @CheckPrivilege(PrivilegeType.MANAGER) public ReviewResponse updateReviewStatus(final Integer memberId, final Integer projectId, final Integer reviewId, final ReviewStatusRequest reviewStatusRequest) { - participantService.checkManagerUnauthorized(memberId, projectId); - Review review = getReview(reviewId); review.updateReviewStatus(reviewStatusRequest.getReviewStatus());