diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomReviewRepositoryImpl.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomReviewRepositoryImpl.kt index 18fa3a0..7d95bc9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomReviewRepositoryImpl.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomReviewRepositoryImpl.kt @@ -20,9 +20,6 @@ class CafeRoomReviewRepositoryImpl( cafeRoomReviewRepository .findAllByRoomId(roomId) - println(entity) - println(entity.size) - return entity.map { val rating = Rating.builder() it.ratingFields.forEach { field -> diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomReviewController.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomReviewController.kt index 4a5d328..071c03c 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomReviewController.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomReviewController.kt @@ -1,11 +1,11 @@ package kr.nagaza.nagazaserver.presenter.restapi.controller +import kr.nagaza.nagazaserver.domain.model.CafeRoomReview import kr.nagaza.nagazaserver.domain.model.rating.Rating import kr.nagaza.nagazaserver.domain.service.CafeRoomReviewService import kr.nagaza.nagazaserver.presenter.restapi.api.CafeRoomReviewApi import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomReviewListResponse -import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomReviewResponse -import kr.nagaza.nagazaserver.presenter.restapi.dto.response.RatingFieldResponse +import kr.nagaza.nagazaserver.util.mapper.review.toDto import org.springframework.stereotype.Controller @Controller @@ -25,24 +25,7 @@ class CafeRoomReviewController( reviewCount = reviewList.size, rating = reviewList.map { it.rating.sum }.average(), roadType = Rating.getRoadType(reviewList.map { it.rating.sum }.average()), - reviewList = - reviewList.map { - CafeRoomReviewResponse( - reviewId = it.reviewId, - userId = it.userId, - fields = - it.rating.fields.map { field -> - RatingFieldResponse( - ratingFieldType = field.key, - value = field.value.value, - ) - }, - rating = it.rating.sum, - roadType = Rating.getRoadType(it.rating.sum), - createdAt = it.createdAt, - content = it.detail.content, - ) - }, + reviewList = reviewList.map(CafeRoomReview::toDto), ) } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/util/mapper/review/ReviewMapper.kt b/src/main/kotlin/kr/nagaza/nagazaserver/util/mapper/review/ReviewMapper.kt new file mode 100644 index 0000000..e2af3f3 --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/util/mapper/review/ReviewMapper.kt @@ -0,0 +1,26 @@ +package kr.nagaza.nagazaserver.util.mapper.review + +import kr.nagaza.nagazaserver.domain.model.CafeRoomReview +import kr.nagaza.nagazaserver.domain.model.rating.field.RatingField +import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomReviewResponse +import kr.nagaza.nagazaserver.presenter.restapi.dto.response.RatingFieldResponse + +fun RatingField.toDto(): RatingFieldResponse { + return RatingFieldResponse( + ratingFieldType = this.type, + value = this.value, + ) +} + +fun CafeRoomReview.toDto(): CafeRoomReviewResponse { + return CafeRoomReviewResponse( + reviewId = this.reviewId, + userId = this.userId, + fields = + this.rating.fields.values.map(RatingField::toDto), + rating = this.rating.sum, + roadType = this.rating.roadType, + createdAt = this.createdAt, + content = this.detail.content, + ) +}