|
| 1 | +package com.somemore.review.controller; |
| 2 | + |
| 3 | +import static org.springframework.data.domain.Sort.Direction.DESC; |
| 4 | + |
| 5 | +import com.somemore.global.common.response.ApiResponse; |
| 6 | +import com.somemore.recruitboard.domain.VolunteerType; |
| 7 | +import com.somemore.review.dto.condition.ReviewSearchCondition; |
| 8 | +import com.somemore.review.dto.response.ReviewResponseDto; |
| 9 | +import com.somemore.review.dto.response.ReviewWithNicknameResponseDto; |
| 10 | +import com.somemore.review.usecase.ReviewQueryUseCase; |
| 11 | +import io.swagger.v3.oas.annotations.tags.Tag; |
| 12 | +import java.util.UUID; |
| 13 | +import lombok.RequiredArgsConstructor; |
| 14 | +import org.springframework.data.domain.Page; |
| 15 | +import org.springframework.data.domain.Pageable; |
| 16 | +import org.springframework.data.web.PageableDefault; |
| 17 | +import org.springframework.web.bind.annotation.GetMapping; |
| 18 | +import org.springframework.web.bind.annotation.PathVariable; |
| 19 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 20 | +import org.springframework.web.bind.annotation.RequestParam; |
| 21 | +import org.springframework.web.bind.annotation.RestController; |
| 22 | + |
| 23 | +@Tag(name = "Review Query API", description = "리뷰 조회 API") |
| 24 | +@RequiredArgsConstructor |
| 25 | +@RequestMapping("/api") |
| 26 | +@RestController |
| 27 | +public class ReviewQueryApiController { |
| 28 | + |
| 29 | + private final ReviewQueryUseCase reviewQueryUseCase; |
| 30 | + |
| 31 | + @GetMapping("/review/{id}") |
| 32 | + public ApiResponse<ReviewResponseDto> getById(@PathVariable Long id) { |
| 33 | + |
| 34 | + return ApiResponse.ok( |
| 35 | + 200, |
| 36 | + reviewQueryUseCase.getReviewById(id), |
| 37 | + "리뷰 단건 조회 성공" |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + @GetMapping("/reviews/center/{centerId}") |
| 42 | + public ApiResponse<Page<ReviewWithNicknameResponseDto>> getReviewsByCenterId( |
| 43 | + @PathVariable UUID centerId, |
| 44 | + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable, |
| 45 | + @RequestParam(required = false) VolunteerType type |
| 46 | + ) { |
| 47 | + ReviewSearchCondition condition = ReviewSearchCondition.builder() |
| 48 | + .volunteerType(type) |
| 49 | + .pageable(pageable) |
| 50 | + .build(); |
| 51 | + |
| 52 | + return ApiResponse.ok( |
| 53 | + 200, |
| 54 | + reviewQueryUseCase.getReviewsByCenterId(centerId, condition), |
| 55 | + "기관 리뷰 리스트 조회 성공" |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + @GetMapping("/reviews/volunteer/{volunteerId}") |
| 60 | + public ApiResponse<Page<ReviewWithNicknameResponseDto>> getReviewsByVolunteerId( |
| 61 | + @PathVariable UUID volunteerId, |
| 62 | + @PageableDefault(sort = "created_at", direction = DESC) Pageable pageable, |
| 63 | + @RequestParam(required = false) VolunteerType type |
| 64 | + ) { |
| 65 | + ReviewSearchCondition condition = ReviewSearchCondition.builder() |
| 66 | + .volunteerType(type) |
| 67 | + .pageable(pageable) |
| 68 | + .build(); |
| 69 | + |
| 70 | + return ApiResponse.ok( |
| 71 | + 200, |
| 72 | + reviewQueryUseCase.getReviewsByVolunteerId(volunteerId, condition), |
| 73 | + "유저 리뷰 리스트 조회 성공" |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | +} |
0 commit comments