|
| 1 | +package devkor.com.teamcback.domain.review.controller; |
| 2 | + |
| 3 | +import devkor.com.teamcback.domain.review.dto.request.CreateReviewReq; |
| 4 | +import devkor.com.teamcback.domain.review.dto.request.ModifyReviewReq; |
| 5 | +import devkor.com.teamcback.domain.review.dto.response.*; |
| 6 | +import devkor.com.teamcback.domain.review.service.ReviewService; |
| 7 | +import devkor.com.teamcback.global.response.CommonResponse; |
| 8 | +import devkor.com.teamcback.global.security.UserDetailsImpl; |
| 9 | +import io.swagger.v3.oas.annotations.Operation; |
| 10 | +import io.swagger.v3.oas.annotations.Parameter; |
| 11 | +import io.swagger.v3.oas.annotations.media.Content; |
| 12 | +import io.swagger.v3.oas.annotations.media.Schema; |
| 13 | +import io.swagger.v3.oas.annotations.responses.ApiResponse; |
| 14 | +import io.swagger.v3.oas.annotations.responses.ApiResponses; |
| 15 | +import jakarta.validation.Valid; |
| 16 | +import lombok.RequiredArgsConstructor; |
| 17 | +import org.springframework.http.MediaType; |
| 18 | +import org.springframework.security.core.annotation.AuthenticationPrincipal; |
| 19 | +import org.springframework.web.bind.annotation.*; |
| 20 | + |
| 21 | +import java.util.List; |
| 22 | + |
| 23 | + |
| 24 | +@RestController |
| 25 | +@RequiredArgsConstructor |
| 26 | +@RequestMapping("/api/reviews") |
| 27 | +public class ReviewController { |
| 28 | + |
| 29 | + private final ReviewService reviewService; |
| 30 | + |
| 31 | + @Operation(summary = "리뷰 태그 종류 검색") |
| 32 | + @ApiResponses(value = { |
| 33 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 34 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 35 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 36 | + }) |
| 37 | + @GetMapping("/tags") |
| 38 | + public CommonResponse<GetReviewTagListRes> getReviewTagList() { |
| 39 | + return CommonResponse.success(reviewService.getReviewTagList()); |
| 40 | + } |
| 41 | + |
| 42 | + @Operation(summary = "리뷰가 있는 장소의 리뷰 목록 포함 상세 검색", |
| 43 | + description = "식당, 카페") |
| 44 | + @ApiResponses(value = { |
| 45 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 46 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 47 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 48 | + }) |
| 49 | + @GetMapping("/places/{placeId}") |
| 50 | + public CommonResponse<GetReviewPlaceDetailRes> getReviewPlaceDetail( |
| 51 | + @Parameter(name = "placeId", description = "장소 ID") @PathVariable Long placeId) { |
| 52 | + |
| 53 | + return CommonResponse.success(reviewService.getReviewPlaceDetail(placeId)); |
| 54 | + } |
| 55 | + |
| 56 | + @Operation(summary = "리뷰가 있는 장소의 리뷰 목록 포함 상세 검색 - 무한스크롤로 리뷰 사진 추가 조회", |
| 57 | + description = "식당, 카페") |
| 58 | + @ApiResponses(value = { |
| 59 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 60 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 61 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 62 | + }) |
| 63 | + @GetMapping("/places/{placeId}/images") |
| 64 | + public CommonResponse<List<SearchReviewImageRes>> getReviewPlaceDetailImages( |
| 65 | + @Parameter(name = "placeId", description = "장소 ID") @PathVariable Long placeId, |
| 66 | + @Parameter(name = "lastFileId", description = "마지막 조회한 사진 id") @RequestParam Long lastFileId) { |
| 67 | + |
| 68 | + return CommonResponse.success(reviewService.getReviewPlaceDetailImages(placeId, lastFileId)); |
| 69 | + } |
| 70 | + |
| 71 | + // TODO: 리뷰 작성 시 포인트 부여 |
| 72 | + @Operation(summary = "리뷰 작성", |
| 73 | + description = "식당, 카페에 대한 리뷰를 작성") |
| 74 | + @ApiResponses(value = { |
| 75 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 76 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 77 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 78 | + }) |
| 79 | + @PostMapping(value = "/places/{placeId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| 80 | + public CommonResponse<CreateReviewRes> createReview( |
| 81 | + @Parameter(description = "사용자정보", required = true) @AuthenticationPrincipal UserDetailsImpl userDetail, |
| 82 | + @Parameter(name = "placeId", description = "장소 ID") @PathVariable Long placeId, |
| 83 | + @Parameter(description = "리뷰 작성 내용", required = true) @Valid @ModelAttribute CreateReviewReq createReviewReq) { |
| 84 | + |
| 85 | + return CommonResponse.success(reviewService.createReview(userDetail.getUser().getUserId(), placeId, createReviewReq)); |
| 86 | + } |
| 87 | + |
| 88 | + @Operation(summary = "리뷰 조회", |
| 89 | + description = "식당, 카페에 대한 리뷰 조회") |
| 90 | + @ApiResponses(value = { |
| 91 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 92 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 93 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 94 | + }) |
| 95 | + @GetMapping("/{reviewId}") |
| 96 | + public CommonResponse<GetReviewRes> getReview( |
| 97 | + @Parameter(name = "reviewId", description = "리뷰 ID") @PathVariable Long reviewId) { |
| 98 | + return CommonResponse.success(reviewService.getReview(reviewId)); |
| 99 | + } |
| 100 | + |
| 101 | + @Operation(summary = "리뷰 수정", |
| 102 | + description = "식당, 카페에 대한 리뷰를 수정") |
| 103 | + @ApiResponses(value = { |
| 104 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 105 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 106 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 107 | + }) |
| 108 | + @PutMapping(value = "/{reviewId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) |
| 109 | + public CommonResponse<ModifyReviewRes> modifyReview( |
| 110 | + @Parameter(description = "사용자정보", required = true) @AuthenticationPrincipal UserDetailsImpl userDetail, |
| 111 | + @Parameter(name = "reviewId", description = "리뷰 ID") @PathVariable Long reviewId, |
| 112 | + @Parameter(description = "리뷰 작성 내용", required = true) @Valid @ModelAttribute ModifyReviewReq modifyReviewReq) { |
| 113 | + |
| 114 | + return CommonResponse.success(reviewService.modifyReview(userDetail.getUser().getUserId(), reviewId, modifyReviewReq)); |
| 115 | + } |
| 116 | + |
| 117 | + // TODO: 리뷰 삭제 시 포인트 제거 |
| 118 | + @Operation(summary = "리뷰 삭제", |
| 119 | + description = "식당, 카페에 대한 리뷰를 삭제") |
| 120 | + @ApiResponses(value = { |
| 121 | + @ApiResponse(responseCode = "200", description = "정상 처리 되었습니다."), |
| 122 | + @ApiResponse(responseCode = "401", description = "권한이 없습니다.", |
| 123 | + content = @Content(schema = @Schema(implementation = CommonResponse.class))), |
| 124 | + }) |
| 125 | + @DeleteMapping( "/{reviewId}") |
| 126 | + public CommonResponse<DeleteReviewRes> deleteReview( |
| 127 | + @Parameter(description = "사용자정보", required = true) @AuthenticationPrincipal UserDetailsImpl userDetail, |
| 128 | + @Parameter(name = "reviewId", description = "리뷰 ID") @PathVariable Long reviewId) { |
| 129 | + return CommonResponse.success(reviewService.deleteReview(userDetail.getUser().getUserId(), reviewId)); |
| 130 | + } |
| 131 | +} |
0 commit comments