Fix: 리뷰 SQL문 에러 해결
This commit is contained in:
parent
6f3ec9e0a1
commit
cc50cc4933
@ -45,7 +45,7 @@ public class ReviewController {
|
||||
public List<ReviewResponse> 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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -18,13 +18,13 @@ public interface ReviewRepository extends JpaRepository<Review, Integer> {
|
||||
|
||||
Optional<Review> 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<Review> findReviewsNativeWithLimit(
|
||||
@Param("projectId") Integer projectId,
|
||||
@Param("reviewStatus") String reviewStatus,
|
||||
@Param("reviewStatus") ReviewStatus reviewStatus,
|
||||
@Param("lastReviewId") Integer lastReviewId,
|
||||
@Param("limit") Integer limit
|
||||
);
|
||||
|
@ -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<ReviewResponse> 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<ReviewResponse> getReviewByProjectId(final Integer memberId, final Integer projectId, final String reviewStatusRequest, final Integer lastReviewId, final Integer limitPage) {
|
||||
// 리뷰 조회 쿼리 호출
|
||||
List<Review> 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<ImageResponse> 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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user