Skip to content

Commit

Permalink
Merge pull request #101 from Begin-Vegan/develop
Browse files Browse the repository at this point in the history
[DEPLOTY] 식당 리뷰 조회 요청 값 수정
  • Loading branch information
jisujeong0 authored Aug 4, 2024
2 parents 9a7a99e + 31ce1ae commit 817dc66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.InvalidParameterException;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -116,27 +117,29 @@ public ResponseEntity<?> findRestaurantById(UserPrincipal userPrincipal, Long re
}

// 식당 리뷰 조회
public ResponseEntity<?> findRestaurantReviewsById(UserPrincipal userPrincipal, RestaurantDetailReq restaurantDetailReq, Boolean isPhoto, Integer page) {
public ResponseEntity<?> findRestaurantReviewsById(UserPrincipal userPrincipal, Long restaurantId, String filter, Boolean isPhoto, Integer page) {

User user = userRepository.findById(userPrincipal.getId())
.orElseThrow(InvalidUserException::new);

Restaurant restaurant = restaurantRepository.findById(restaurantDetailReq.getRestaurantId())
Restaurant restaurant = restaurantRepository.findById(restaurantId)
.orElseThrow(InvalidRestaurantException::new);

Page<Review> reviewPage;
// 최신순
if (restaurantDetailReq.getFilter().equals("date")) {
if (filter.equals("date")) {
PageRequest pageable = PageRequest.of(page, 10, Sort.by(Sort.Direction.DESC, "modifiedDate"));
// photo 여부에 따라
reviewPage = isPhoto ?
reviewRepository.findReviewsByRestaurantAndReviewType(restaurant, pageable, ReviewType.PHOTO) :
reviewRepository.findReviewsByRestaurant(restaurant, pageable);
} else {
} else if (filter.equals("recommendation")){
Pageable pageable = PageRequest.of(page, 10);
reviewPage = isPhoto ?
reviewRepository.findReviewsByRestaurantAndReviewTypeOrderByRecommendationCount(pageable, restaurant, ReviewType.PHOTO) :
reviewRepository.findReviewsByRestaurantOrderByRecommendationCount(pageable, restaurant);
} else {
throw new InvalidParameterException("유효한 값이 아닙니다.");
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@ public ResponseEntity<?> findRestaurantById(
return restaurantService.findRestaurantById(userPrincipal, restaurantId, latitude, longitude);
}

@Operation(summary = "식당/카페 리뷰 조희", description = "식당/카페 리뷰를 조희합니다.")
@Operation(summary = "식당/카페 리뷰 조회", description = "식당/카페 리뷰를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "식당/카페 리뷰 조회 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ReviewListRes.class))}),
@ApiResponse(responseCode = "400", description = "식당/카페 리뷰 조회 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@GetMapping("/review")
@GetMapping("/{restaurant-id}/review")
public ResponseEntity<?> findRestaurantReviewsById(
@Parameter(description = "AccessToken을 입력해주세요") @CurrentUser UserPrincipal userPrincipal,
@Parameter(description = "RestaurantDetailReq를 참고해주세요.", required = true) @RequestBody RestaurantDetailReq restaurantDetailReq,
@Parameter(description = "식당/카페를 ID로 조회합니다.", required = true) @PathVariable(value = "restaurant-id") Long restaurantId,
@Parameter(description = "정렬 필터입니다. date와 recommendation이 존재하며, 기본값은 date입니다.", required = true) @RequestParam(defaultValue = "false") String filter,
@Parameter(description = "'포토 리뷰만 보기' 선택 여부입니다. 기본값은 false입니다.", required = true) @RequestParam(defaultValue = "false") Boolean isPhoto,
@Parameter(description = "식당/카페의 리뷰 목록을 페이지별로 조회합니다. **Page는 0부터 시작합니다!**", required = true) @RequestParam(value = "page") Integer page
) {
return restaurantService.findRestaurantReviewsById(userPrincipal, restaurantDetailReq, isPhoto, page);
return restaurantService.findRestaurantReviewsById(userPrincipal, restaurantId, filter, isPhoto, page);
}

@Operation(summary = "식당/카페 스크랩", description = "식당/카페를 스크랩합니다.")
Expand Down

0 comments on commit 817dc66

Please sign in to comment.