Fix: 리뷰 SQL문 에러 해결
This commit is contained in:
parent
6f3ec9e0a1
commit
cc50cc4933
@ -45,7 +45,7 @@ public class ReviewController {
|
|||||||
public List<ReviewResponse> getReviewByProject(
|
public List<ReviewResponse> getReviewByProject(
|
||||||
@CurrentUser final Integer memberId,
|
@CurrentUser final Integer memberId,
|
||||||
@PathVariable("project_id") final Integer projectId,
|
@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 = "마지막 리뷰 id", description = "마지막 리뷰 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastReviewId,
|
||||||
@Parameter(name = "가져올 리뷰 수", description = "가져올 리뷰 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) {
|
@Parameter(name = "가져올 리뷰 수", description = "가져올 리뷰 수 default = 10", example = "20") @RequestParam(defaultValue = "10") Integer limitPage) {
|
||||||
return reviewService.getReviewByProjectId(memberId, projectId, reviewStatusRequest, lastReviewId, limitPage);
|
return reviewService.getReviewByProjectId(memberId, projectId, reviewStatusRequest, lastReviewId, limitPage);
|
||||||
|
@ -16,4 +16,8 @@ public class ReviewStatusRequest {
|
|||||||
@Schema(description = "리뷰 상태", example = "거부")
|
@Schema(description = "리뷰 상태", example = "거부")
|
||||||
@NotNull(message = "상태를 입력하세요.")
|
@NotNull(message = "상태를 입력하세요.")
|
||||||
private ReviewStatus reviewStatus;
|
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);
|
Optional<Review> findByIdAndMemberId(Integer reviewId, Integer memberId);
|
||||||
|
|
||||||
@Query(value = "SELECT r.*, m.* " +
|
@Query("SELECT r, m " +
|
||||||
"FROM review r JOIN member m ON r.member_id = m.member_id " +
|
"FROM Review r JOIN Member m ON r.id = m.id " +
|
||||||
"WHERE r.project_id = :projectId AND (:reviewStatus IS NULL OR r.status = :reviewStatus) AND (:lastReviewId IS NULL OR r.review_id < :lastReviewId) " +
|
"WHERE r.project.id = :projectId AND (:reviewStatus IS NULL OR r.reviewStatus = :reviewStatus) AND (:lastReviewId IS NULL OR r.id < :lastReviewId) " +
|
||||||
"ORDER BY r.review_id DESC LIMIT :limit", nativeQuery = true)
|
"ORDER BY r.id DESC LIMIT :limit")
|
||||||
List<Review> findReviewsNativeWithLimit(
|
List<Review> findReviewsNativeWithLimit(
|
||||||
@Param("projectId") Integer projectId,
|
@Param("projectId") Integer projectId,
|
||||||
@Param("reviewStatus") String reviewStatus,
|
@Param("reviewStatus") ReviewStatus reviewStatus,
|
||||||
@Param("lastReviewId") Integer lastReviewId,
|
@Param("lastReviewId") Integer lastReviewId,
|
||||||
@Param("limit") Integer limit
|
@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.image.repository.ImageRepository;
|
||||||
import com.worlabel.domain.member.entity.Member;
|
import com.worlabel.domain.member.entity.Member;
|
||||||
import com.worlabel.domain.member.repository.MemberRepository;
|
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.participant.service.ParticipantService;
|
||||||
import com.worlabel.domain.project.entity.Project;
|
import com.worlabel.domain.project.entity.Project;
|
||||||
import com.worlabel.domain.project.repository.ProjectRepository;
|
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.entity.dto.ReviewStatusRequest;
|
||||||
import com.worlabel.domain.review.repository.ReviewImageRepository;
|
import com.worlabel.domain.review.repository.ReviewImageRepository;
|
||||||
import com.worlabel.domain.review.repository.ReviewRepository;
|
import com.worlabel.domain.review.repository.ReviewRepository;
|
||||||
|
import com.worlabel.global.annotation.CheckPrivilege;
|
||||||
import com.worlabel.global.exception.CustomException;
|
import com.worlabel.global.exception.CustomException;
|
||||||
import com.worlabel.global.exception.ErrorCode;
|
import com.worlabel.global.exception.ErrorCode;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -40,10 +42,8 @@ public class ReviewService {
|
|||||||
private final ProjectRepository projectRepository;
|
private final ProjectRepository projectRepository;
|
||||||
private final ParticipantService participantService;
|
private final ParticipantService participantService;
|
||||||
|
|
||||||
|
@CheckPrivilege(PrivilegeType.EDITOR)
|
||||||
public ReviewResponse createReview(final Integer memberId, final Integer projectId, final ReviewRequest reviewRequest) {
|
public ReviewResponse createReview(final Integer memberId, final Integer projectId, final ReviewRequest reviewRequest) {
|
||||||
// 권한 체크 편집자 이상만 리뷰 신청 가능
|
|
||||||
participantService.checkEditorUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
Project project = getProject(projectId);
|
Project project = getProject(projectId);
|
||||||
Member member = getMember(memberId);
|
Member member = getMember(memberId);
|
||||||
|
|
||||||
@ -69,13 +69,12 @@ public class ReviewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ReviewResponse> getReviewByProjectId(final Integer memberId, final Integer projectId, final ReviewStatusRequest reviewStatusRequest, final Integer lastReviewId, final Integer limitPage) {
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
participantService.checkViewerUnauthorized(memberId, projectId);
|
public List<ReviewResponse> getReviewByProjectId(final Integer memberId, final Integer projectId, final String reviewStatusRequest, final Integer lastReviewId, final Integer limitPage) {
|
||||||
|
|
||||||
// 리뷰 조회 쿼리 호출
|
// 리뷰 조회 쿼리 호출
|
||||||
List<Review> reviews = reviewRepository.findReviewsNativeWithLimit(
|
List<Review> reviews = reviewRepository.findReviewsNativeWithLimit(
|
||||||
projectId,
|
projectId,
|
||||||
reviewStatusRequest != null ? reviewStatusRequest.getReviewStatus().toValue() : null,
|
reviewStatusRequest == null ? null : ReviewStatus.valueOf(reviewStatusRequest),
|
||||||
lastReviewId,
|
lastReviewId,
|
||||||
limitPage
|
limitPage
|
||||||
);
|
);
|
||||||
@ -88,9 +87,8 @@ public class ReviewService {
|
|||||||
|
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
@CheckPrivilege(PrivilegeType.VIEWER)
|
||||||
public ReviewDetailResponse getReviewById(final Integer memberId, final Integer projectId, final Integer reviewId) {
|
public ReviewDetailResponse getReviewById(final Integer memberId, final Integer projectId, final Integer reviewId) {
|
||||||
participantService.checkViewerUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
Review review = getReview(reviewId);
|
Review review = getReview(reviewId);
|
||||||
|
|
||||||
List<ImageResponse> images = reviewImageRepository.findAllByReviewIdWithImage(reviewId).stream()
|
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) {
|
public ReviewResponse updateReviewStatus(final Integer memberId, final Integer projectId, final Integer reviewId, final ReviewStatusRequest reviewStatusRequest) {
|
||||||
participantService.checkManagerUnauthorized(memberId, projectId);
|
|
||||||
|
|
||||||
Review review = getReview(reviewId);
|
Review review = getReview(reviewId);
|
||||||
review.updateReviewStatus(reviewStatusRequest.getReviewStatus());
|
review.updateReviewStatus(reviewStatusRequest.getReviewStatus());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user