diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt index f157a36..c14591c 100644 --- a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt +++ b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt @@ -7,6 +7,7 @@ import org.meogo.domain.review.service.CreateReviewService import org.meogo.domain.review.service.DeleteReviewService import org.meogo.domain.review.service.ModifyReviewService import org.meogo.domain.review.service.QueryAllBySchoolIdService +import org.meogo.domain.review.service.QueryReviewPictureService import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping @@ -26,7 +27,8 @@ class ReviewController( private val createReviewService: CreateReviewService, private val queryAllBySchoolIdService: QueryAllBySchoolIdService, private val modifyReviewService: ModifyReviewService, - private val deleteReviewService: DeleteReviewService + private val deleteReviewService: DeleteReviewService, + private val queryReviewPictureService: QueryReviewPictureService ) { @PostMapping @ResponseStatus(value = HttpStatus.CREATED) @@ -48,4 +50,8 @@ class ReviewController( @ResponseStatus(value = HttpStatus.NO_CONTENT) fun delete(@RequestParam(name = "review_id") reviewId: Long) = deleteReviewService.deleteReview(reviewId) + + @GetMapping("/pic") + fun queryReviewPicture(@RequestParam(name = "school_id") schoolId: Int) = + queryReviewPictureService.queryReviewPicture(schoolId) } diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt b/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt new file mode 100644 index 0000000..bdfd271 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt @@ -0,0 +1,5 @@ +package org.meogo.domain.review.presentation.dto.response + +data class ReviewPictureResponse( + val image: String +) diff --git a/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt b/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt new file mode 100644 index 0000000..3214472 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt @@ -0,0 +1,22 @@ +package org.meogo.domain.review.service + +import org.meogo.domain.review.presentation.dto.response.ReviewPictureResponse +import org.meogo.domain.review.repository.ReviewRepository +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class QueryReviewPictureService( + private val reviewRepository: ReviewRepository +) { + + @Transactional + fun queryReviewPicture(schoolId: Int): List { + val reviews = reviewRepository.findAllBySchoolId(schoolId) ?: return emptyList() + + val pictures = reviews + .mapNotNull { it.picture?.let { pic -> ReviewPictureResponse(pic) } } + + return pictures + } +}