-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from nhnacademy-be5-T3Team/feature/review
Feature/review
- Loading branch information
Showing
18 changed files
with
1,031 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 157 additions & 11 deletions
168
src/main/java/com/t3t/frontserver/review/adaptor/ReviewAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
src/main/java/com/t3t/frontserver/review/client/ReviewApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/t3t/frontserver/review/client/ReviewFormApiClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.