Skip to content

Commit

Permalink
Merge pull request #66 from Team-Growthook/feat/#60-review-detail-get…
Browse files Browse the repository at this point in the history
…-api

[FEAT] 리뷰 내용 상세 조회 API
  • Loading branch information
yeseul106 authored Jan 8, 2024
2 parents 9083bf7 + 8c01663 commit 80a663d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<ReviewDetailGetResponseDto> getReviewDetail(@PathVariable("actionPlanId") Long actionPlanId) {
return ApiResponse.success(SuccessStatus.GET_REVIEW_DETAIL, reviewService.getReviewDetail(actionPlanId));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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<Review, Long> {

Optional<Review> findReviewByActionPlanId(Long actionPlanId);

default Review findReviewByActionPlanIdOrThrow(Long actionPlanId) {
return findReviewByActionPlanId(actionPlanId)
.orElseThrow(() -> new NotFoundException(ErrorStatus.NOT_FOUND_REVIEW.getMessage()));
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ErrorStatus {
NOT_FOUND_CAVE("해당하는 동굴이 없습니다."),
NOT_FOUND_SEED("해당하는 씨앗이 없습니다."),
NOT_FOUND_ACTIONPLAN("해당하는 액션 플랜이 없습니다."),
NOT_FOUND_REVIEW("해당하는 액션플랜에 작성된 리뷰가 없습니다."),

/**
* 500 SERVER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum SuccessStatus {
* review
*/
POST_REVIEW_SUCCESS(HttpStatus.CREATED, "리뷰 생성 성공"),
GET_REVIEW_DETAIL(HttpStatus.OK, "리뷰 내용 상세 조회 성공"),
;

private final HttpStatus httpStatus;
Expand Down

0 comments on commit 80a663d

Please sign in to comment.