Skip to content

Commit

Permalink
Merge pull request #105 from nhnacademy-be5-T3Team/feature/review
Browse files Browse the repository at this point in the history
Feature/review
  • Loading branch information
Yujin-nKim authored May 15, 2024
2 parents 949461e + dd3ae14 commit 031ba7e
Show file tree
Hide file tree
Showing 18 changed files with 1,031 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import com.t3t.frontserver.index.OrderFormRequest;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.review.adaptor.ReviewAdaptor;
import com.t3t.frontserver.review.response.ReviewResponse;
import com.t3t.frontserver.review.client.ReviewApiClient;
import com.t3t.frontserver.review.model.response.ReviewResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -26,7 +26,7 @@
public class BookController {
private final CategoryApiClient categoryAdaptor;
private final BookApiClient bookApiClient;
private final ReviewAdaptor reviewAdaptor;
private final ReviewApiClient reviewApiClient;

@GetMapping("books/{bookId}")
public String getBook(Model model, @PathVariable Long bookId,
Expand Down Expand Up @@ -69,7 +69,7 @@ private BookDetailResponse getDataFromBookAdaptor(Long bookId) {
}

private PageResponse<ReviewResponse> getDataFromReviewAdaptor(Long bookId, int pageNo) {
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> reviewsResponse = reviewAdaptor.getBook(bookId, pageNo);
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> reviewsResponse = reviewApiClient.findReviewsByBookId(bookId, pageNo);
return handleResponse(reviewsResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public ApiDataFetchException() {
public ApiDataFetchException(int statusCode) {
super(String.format("%s (%s)", DEFAULT_MESSAGE, statusCode));
}

public ApiDataFetchException(String message) {
super(DEFAULT_MESSAGE + message);
}
}
168 changes: 157 additions & 11 deletions src/main/java/com/t3t/frontserver/review/adaptor/ReviewAdaptor.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,162 @@
package com.t3t.frontserver.review.adaptor;

import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.review.response.ReviewResponse;
import org.springframework.cloud.openfeign.FeignClient;
import com.t3t.frontserver.review.client.ReviewApiClient;
import com.t3t.frontserver.review.client.ReviewFormApiClient;
import com.t3t.frontserver.review.model.request.ReviewCommentUpdateRequest;
import com.t3t.frontserver.review.model.request.ReviewRegisterRequest;
import com.t3t.frontserver.review.model.response.ReviewResponse;
import com.t3t.frontserver.util.FeignClientUtils;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "reviewAdaptor", url = "${t3t.feignClient.url}")
public interface ReviewAdaptor {
@GetMapping(value = "/t3t/bookstore/reviews/book/{bookId}")
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> getBook(@PathVariable Long bookId, @RequestParam int pageNo);
}
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Objects;
import java.util.Optional;


@Slf4j
@Component
@RequiredArgsConstructor
public class ReviewAdaptor {
private final ReviewApiClient reviewApiClient;
private final ReviewFormApiClient reviewFormApiClient;

/**
* 리뷰 작성 가능 여부를 확인
* @param memberId 회원 식별자
* @param bookId 도서 식별자
* @param orderDetailId 주문상세 ID
* @return 리뷰 작성 가능 여부
* @author Yujin-nKim(김유진)
*/
public boolean checkReviewCapability(Long memberId, Long bookId, Long orderDetailId) {
try {
return Optional.ofNullable(reviewApiClient.checkReviewCapability(memberId, bookId, orderDetailId).getBody())
.map(BaseResponse::getData)
.orElseThrow(ApiDataFetchException::new);
} catch (FeignException e) {
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 생성 요청
* @param request 리뷰 생성 요청 객체
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
public void createReview(ReviewRegisterRequest request) {
try {
reviewFormApiClient.createReview(request);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 사용자 식별자에 해당하는 리뷰 페이지 조회
* @param memberId 회원 식별자
* @param pageNo 페이지 번호
* @param pageSize 페이지 크기
* @param sortBy 정렬 기준
* @return 주어진 회원 식별자에 대한 리뷰 페이지 응답
* @author Yujin-nKim(김유진)
*/
public PageResponse<ReviewResponse> findReviewsByMemberId(Long memberId, int pageNo, int pageSize, String sortBy) {
try {
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> response = reviewApiClient.findReviewsByMemberId(memberId, pageNo, pageSize, sortBy);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 상세 조회
* @param reviewId 리뷰 ID
* @return 리뷰 상세
* @author Yujin-nKim(김유진)
*/
public ReviewResponse findReviewByReviewId(Long reviewId) {
try {
return Optional.ofNullable(reviewApiClient.findReviewByReviewId(reviewId).getBody())
.map(BaseResponse::getData)
.orElseThrow(ApiDataFetchException::new);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 comment 수정 요청
* @param reviewId 수정할 review ID
* @param request 리뷰 수정 요청 객체
* @author Yujin-nKim(김유진)
*/
public void updateReviewDetail(Long reviewId, ReviewCommentUpdateRequest request) {
try {
reviewApiClient.updateReviewDetail(reviewId, request);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 score 수정 요청
* @param reviewId 수정할 review ID
* @param score 수정할 점수
* @author Yujin-nKim(김유진)
*/
public void updateReviewScore(Long reviewId, Integer score) {
try {
reviewApiClient.updateReviewScore(reviewId, score);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 이미지 삭제 요청
* @param reviewImageName 삭제할 이미지 name
* @author Yujin-nKim(김유진)
*/
public void deleteReviewImage(String reviewImageName) {
try {
reviewApiClient.deleteReviewImage(reviewImageName);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}

/**
* 리뷰 이미지 추가 요청
* @param reviewId 수정할 review ID
* @param imageList 추가할 이미지
* @author Yujin-nKim(김유진)
*/
public void addReviewImage(Long reviewId, List<MultipartFile> imageList) {
try {
reviewFormApiClient.addReviewImage(reviewId, imageList);
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException(FeignClientUtils.getMessageFromFeignException(e));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.t3t.frontserver.review.client;

import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.model.response.PageResponse;
import com.t3t.frontserver.review.model.request.ReviewCommentUpdateRequest;
import com.t3t.frontserver.review.model.response.ReviewResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@FeignClient(name = "ReviewApiClient", url = "${t3t.feignClient.url}")
public interface ReviewApiClient {

/**
* 책 ID에 해당하는 리뷰 페이지 조회
* @param bookId 리뷰를 검색할 책의 식별자
* @param pageNo 페이지 번호
* @return 주어진 책 식별자에 대한 리뷰 페이지 응답
* @author Yujin-nKim(김유진)
*/
@GetMapping(value = "/t3t/bookstore/reviews/books/{bookId}")
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> findReviewsByBookId(
@PathVariable Long bookId,
@RequestParam(value = "pageNo", defaultValue = "0", required = false) int pageNo);

/**
* 리뷰 작성 가능 여부를 확인
* @param memberId 회원 식별자
* @param bookId 도서 식별자
* @param orderDetailId 주문상세 ID
* @return 리뷰 작성 가능 여부
* @author Yujin-nKim(김유진)
*/
@GetMapping("/t3t/bookstore/reviews/members/{memberId}/capability")
ResponseEntity<BaseResponse<Boolean>> checkReviewCapability(@PathVariable Long memberId, @RequestParam Long bookId, @RequestParam Long orderDetailId);

/**
* 사용자 식별자에 해당하는 리뷰 페이지 조회
* @param memberId 회원 식별자
* @param pageNo 페이지 번호
* @param pageSize 페이지 크기
* @param sortBy 정렬 기준
* @return 주어진 회원 식별자에 대한 리뷰 페이지 응답
* @author Yujin-nKim(김유진)
*/
@GetMapping("/t3t/bookstore/reviews/members/{memberId}")
ResponseEntity<BaseResponse<PageResponse<ReviewResponse>>> findReviewsByMemberId(
@PathVariable Long memberId,
@RequestParam(value = "pageNo", defaultValue = "0", required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize,
@RequestParam(value = "sortBy", defaultValue = "reviewCreatedAt", required = false) String sortBy);

/**
* 리뷰 상세 조회
* @param reviewId 리뷰 ID
* @return 리뷰 상세
* @author Yujin-nKim(김유진)
*/
@GetMapping("/t3t/bookstore/reviews/{reviewId}")
ResponseEntity<BaseResponse<ReviewResponse>> findReviewByReviewId(@PathVariable Long reviewId);

/**
* 리뷰 comment 수정 요청
* @param reviewId 수정할 review ID
* @param request 리뷰 수정 요청 객체
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@PutMapping("/t3t/bookstore/reviews/{reviewId}/comment")
ResponseEntity<BaseResponse<Void>> updateReviewDetail(@PathVariable Long reviewId,
@RequestBody ReviewCommentUpdateRequest request);

/**
* 리뷰 score 수정 요청
* @param reviewId 수정할 review ID
* @param score 수정할 점수
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@PutMapping("/t3t/bookstore/reviews/{reviewId}/score")
ResponseEntity<BaseResponse<Void>> updateReviewScore(@PathVariable Long reviewId,
@RequestParam Integer score);

/**
* 리뷰 이미지 삭제 요청
* @param reviewImageName 삭제할 이미지 name
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@DeleteMapping("/t3t/bookstore/reviews/image")
ResponseEntity<BaseResponse<Void>> deleteReviewImage(@RequestParam String reviewImageName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.t3t.frontserver.review.client;

import com.t3t.frontserver.config.FormConfiguration;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.review.model.request.ReviewRegisterRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@FeignClient(name = "reviewFormApiClient", url = "${t3t.feignClient.url}", configuration = FormConfiguration.class)
public interface ReviewFormApiClient {

/**
* 리뷰 생성 요청
* @param request 리뷰 생성 요청 객체
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@PostMapping(value = "/t3t/bookstore/reviews", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResponseEntity<BaseResponse<Void>> createReview(@ModelAttribute ReviewRegisterRequest request);

/**
* 리뷰 이미지 추가 요청
* @param reviewId 수정할 review ID
* @param imageList 추가할 이미지
* @return 200 OK, 성공 메세지
* @author Yujin-nKim(김유진)
*/
@PostMapping(value = "/t3t/bookstore/reviews/{reviewId}/image", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
ResponseEntity<BaseResponse<Void>> addReviewImage(@PathVariable Long reviewId,
@RequestPart List<MultipartFile> imageList);
}
Loading

0 comments on commit 031ba7e

Please sign in to comment.