-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d4e850
commit a3c246d
Showing
3 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
12 changes: 10 additions & 2 deletions
12
src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
package org.meogo.domain.review.presentation | ||
|
||
import lombok.RequiredArgsConstructor | ||
import org.meogo.domain.review.presentation.dto.ReviewRequest | ||
import org.meogo.domain.review.presentation.dto.request.ReviewRequest | ||
import org.meogo.domain.review.service.CreateReviewService | ||
import org.meogo.domain.review.service.QueryAllBySchoolIdService | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
import javax.validation.Valid | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/review") | ||
class ReviewController( | ||
private val createReviewService: CreateReviewService | ||
private val createReviewService: CreateReviewService, | ||
private val queryAllBySchoolIdService: QueryAllBySchoolIdService | ||
) { | ||
@PostMapping | ||
fun create( | ||
@Valid @RequestBody | ||
request: ReviewRequest | ||
) = | ||
createReviewService.execute(request) | ||
|
||
@GetMapping("/query") | ||
fun queryAllBySchoolId(@RequestParam(name = "school_id") schoolId: Int) = | ||
queryAllBySchoolIdService.queryAllBySchoolId(schoolId) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/kotlin/org/meogo/domain/review/service/QueryAllBySchoolIdService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.meogo.domain.review.service | ||
|
||
import org.meogo.domain.review.presentation.dto.response.ReviewResponse | ||
import org.meogo.domain.review.repository.ReviewRepository | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Service | ||
class QueryAllBySchoolIdService( | ||
private val reviewRepository: ReviewRepository | ||
) { | ||
@Transactional(readOnly = true) | ||
fun queryAllBySchoolId(schoolId: Int): List<ReviewResponse> { | ||
val reviews = reviewRepository.findAllBySchoolId(schoolId) | ||
|
||
return reviews.map { review -> | ||
ReviewResponse( | ||
id = review.id, | ||
content = review.content, | ||
date = format(review.date), | ||
userName = review.userName, | ||
star = review.star, | ||
picture = review.picture ?: "" | ||
) | ||
}.sortedBy { it.id } | ||
} | ||
|
||
private fun format(date: LocalDateTime) = | ||
date.format(DateTimeFormatter.ofPattern("MM.dd HH:mm")).toString() | ||
} |