Skip to content

Commit

Permalink
Merge branch '14-refactor' into 13-modif-review
Browse files Browse the repository at this point in the history
  • Loading branch information
meltapplee committed Sep 5, 2024
2 parents 41bf6c4 + b2cf303 commit bb66740
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
33 changes: 23 additions & 10 deletions src/main/kotlin/org/meogo/domain/review/domain/Review.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,32 @@ class Review(
@Id
val id: Long = 0,

@Column(nullable = false)
val date: LocalDateTime,

@Column(columnDefinition = "BINARY(16)")
@Column(name = "user_id", columnDefinition = "BINARY(16)")
val userId: UUID,

val userName: String,

@Column(name = "school_id", nullable = false)
val schoolId: Int,

val star: Long,

val content: String,

val picture: String?

)
@Column(nullable = false)
var star: Float,

@Column(nullable = false)
var content: String,

var picture: String?

) {
fun updateReview(
content: String,
star: Float,
picture: String?
): Review {
this.content = content
this.star = star
this.picture = picture
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ data class ReviewRequest(
@field:Size(min = 1, max = 300)
val content: String,
val schoolId: Int,
val star: Long,
val star: Float,
val image: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ data class ReviewResponse(
val content: String,
val date: String,
val userName: String,
val star: Long,
val star: Float,
val picture: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class CreateReviewService(
Review(
date = LocalDateTime.now(),
userId = user.id!!,
userName = user.name,
schoolId = request.schoolId,
star = request.star,
content = request.content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ package org.meogo.domain.review.service

import org.meogo.domain.review.presentation.dto.response.ReviewResponse
import org.meogo.domain.review.repository.ReviewRepository
import org.meogo.domain.user.facade.UserFacade
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
private val reviewRepository: ReviewRepository,
private val userFacade: UserFacade
) {

@Transactional(readOnly = true)
fun queryAllBySchoolId(schoolId: Int): List<ReviewResponse> {
val reviews = reviewRepository.findAllBySchoolId(schoolId)

return reviews.map { review ->
ReviewResponse(
id = review.id,
userName = userFacade.getUserById(review.userId).name,
content = review.content,
date = format(review.date),
userName = review.userName,
star = review.star,
picture = review.picture ?: ""
)
Expand Down

0 comments on commit bb66740

Please sign in to comment.