Skip to content

Commit

Permalink
add :: queryReviewPicture api
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Sep 5, 2024
1 parent b379d1a commit 96e30ee
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.meogo.domain.review.presentation.dto.response

data class ReviewPictureResponse(
val image: String
)
Original file line number Diff line number Diff line change
@@ -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<ReviewPictureResponse> {
val reviews = reviewRepository.findAllBySchoolId(schoolId) ?: return emptyList()

val pictures = reviews
.mapNotNull { it.picture?.let { pic -> ReviewPictureResponse(pic) } }

return pictures
}
}

0 comments on commit 96e30ee

Please sign in to comment.