From 8c01663c87a29b760f195d6c833886e1cdd91d21 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Mon, 8 Jan 2024 03:24:59 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=A6=AC=EB=B7=B0=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/controller/ReviewController.java | 9 +++++++++ .../response/ReviewDetailGetResponseDto.java | 16 ++++++++++++++++ .../review/repository/ReviewRepository.java | 11 +++++++++++ .../api/review/service/ReviewService.java | 3 +++ .../api/review/service/ReviewServiceImpl.java | 18 ++++++++++++++++-- .../common/response/ErrorStatus.java | 1 + .../common/response/SuccessStatus.java | 1 + 7 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 growthookServer/src/main/java/com/example/growthookserver/api/review/dto/response/ReviewDetailGetResponseDto.java diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/review/controller/ReviewController.java b/growthookServer/src/main/java/com/example/growthookserver/api/review/controller/ReviewController.java index 52a9dcf..8425446 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/review/controller/ReviewController.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/review/controller/ReviewController.java @@ -1,6 +1,7 @@ package com.example.growthookserver.api.review.controller; import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto; +import com.example.growthookserver.api.review.dto.response.ReviewDetailGetResponseDto; import com.example.growthookserver.api.review.service.ReviewService; import com.example.growthookserver.common.response.ApiResponse; import com.example.growthookserver.common.response.SuccessStatus; @@ -9,6 +10,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -31,4 +33,11 @@ public ApiResponse createReview(@PathVariable("actionPlanId") Long actionPlanId, return ApiResponse.success( SuccessStatus.POST_REVIEW_SUCCESS.getStatusCode(), SuccessStatus.POST_REVIEW_SUCCESS.getMessage()); } + + @GetMapping("actionplan/{actionPlanId}/review") + @ResponseStatus(HttpStatus.OK) + @Operation(summary = "ReveiwGet", description = "리뷰 상세 조회 API입니다.") + public ApiResponse getReviewDetail(@PathVariable("actionPlanId") Long actionPlanId) { + return ApiResponse.success(SuccessStatus.GET_REVIEW_DETAIL, reviewService.getReviewDetail(actionPlanId)); + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/review/dto/response/ReviewDetailGetResponseDto.java b/growthookServer/src/main/java/com/example/growthookserver/api/review/dto/response/ReviewDetailGetResponseDto.java new file mode 100644 index 0000000..56704ff --- /dev/null +++ b/growthookServer/src/main/java/com/example/growthookserver/api/review/dto/response/ReviewDetailGetResponseDto.java @@ -0,0 +1,16 @@ +package com.example.growthookserver.api.review.dto.response; + +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(staticName = "of") +public class ReviewDetailGetResponseDto { + private String actionPlan; + private Boolean isScraped; + private String content; + private String reviewDate; +} diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/review/repository/ReviewRepository.java b/growthookServer/src/main/java/com/example/growthookserver/api/review/repository/ReviewRepository.java index fb569e5..704761f 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/review/repository/ReviewRepository.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/review/repository/ReviewRepository.java @@ -1,8 +1,19 @@ package com.example.growthookserver.api.review.repository; +import com.example.growthookserver.api.cave.domain.Cave; import com.example.growthookserver.api.review.domain.Review; +import com.example.growthookserver.common.exception.NotFoundException; +import com.example.growthookserver.common.response.ErrorStatus; +import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface ReviewRepository extends JpaRepository { + Optional findReviewByActionPlanId(Long actionPlanId); + + default Review findReviewByActionPlanIdOrThrow(Long actionPlanId) { + return findReviewByActionPlanId(actionPlanId) + .orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_REVIEW.getMessage())); + } + } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewService.java b/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewService.java index 9744213..3afa37b 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewService.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewService.java @@ -1,10 +1,13 @@ package com.example.growthookserver.api.review.service; import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto; +import com.example.growthookserver.api.review.dto.response.ReviewDetailGetResponseDto; public interface ReviewService{ //* 액션 플랜별 리뷰 작성 void createReview(Long actionPlanId, ReviewCreateRequestDto reviewCreateRequestDto); + //* 리뷰 내용 상세 조회 + ReviewDetailGetResponseDto getReviewDetail(Long actionPlanId); } diff --git a/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewServiceImpl.java b/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewServiceImpl.java index 0bda40d..45f1113 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewServiceImpl.java +++ b/growthookServer/src/main/java/com/example/growthookserver/api/review/service/ReviewServiceImpl.java @@ -4,9 +4,10 @@ import com.example.growthookserver.api.actionplan.repository.ActionPlanRepository; import com.example.growthookserver.api.review.domain.Review; import com.example.growthookserver.api.review.dto.request.ReviewCreateRequestDto; +import com.example.growthookserver.api.review.dto.response.ReviewDetailGetResponseDto; import com.example.growthookserver.api.review.repository.ReviewRepository; -import com.example.growthookserver.api.seed.domain.Seed; -import com.example.growthookserver.api.seed.repository.SeedRepository; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,4 +30,17 @@ public void createReview(Long actionPlanId, ReviewCreateRequestDto reviewCreateR .build(); reviewRepository.save(review); } + + @Override + public ReviewDetailGetResponseDto getReviewDetail(Long actionPlanId) { + Review review = reviewRepository.findReviewByActionPlanIdOrThrow(actionPlanId); + ActionPlan actionPlan = review.getActionPlan(); + return ReviewDetailGetResponseDto.of(actionPlan.getContent(), actionPlan.getIsScraped(), + review.getContent(), formatReviewDate(review.getCreatedAt())); + } + + private String formatReviewDate(LocalDateTime reviewDate) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy.MM.dd"); + return reviewDate.format(formatter); + } } diff --git a/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java b/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java index 835502e..a63ca96 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java +++ b/growthookServer/src/main/java/com/example/growthookserver/common/response/ErrorStatus.java @@ -34,6 +34,7 @@ public enum ErrorStatus { NOT_FOUND_CAVE("해당하는 동굴이 없습니다."), NOT_FOUND_SEED("해당하는 씨앗이 없습니다."), NOT_FOUND_ACTIONPLAN("해당하는 액션 플랜이 없습니다."), + NOT_FOUND_REVIEW("해당하는 액션플랜에 작성된 리뷰가 없습니다."), /** * 500 SERVER_ERROR diff --git a/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java b/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java index ed1aa24..05842d3 100644 --- a/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java +++ b/growthookServer/src/main/java/com/example/growthookserver/common/response/SuccessStatus.java @@ -55,6 +55,7 @@ public enum SuccessStatus { * review */ POST_REVIEW_SUCCESS(HttpStatus.CREATED, "리뷰 생성 성공"), + GET_REVIEW_DETAIL(HttpStatus.OK, "리뷰 내용 상세 조회 성공"), ; private final HttpStatus httpStatus;