Skip to content

Commit

Permalink
refactor: review mapper를 만들어 dto 변환을 처리하자
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed Jan 30, 2024
1 parent 2a4e702 commit cdb308f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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),
)
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
}

0 comments on commit cdb308f

Please sign in to comment.