diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoomReview.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoomReview.kt index dd0c63a..395568a 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoomReview.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoomReview.kt @@ -17,4 +17,5 @@ data class CafeRoomReviewDetail( val userCnt: Int, val isCleared: Boolean, val usedHintCnt: Int, + val content: String?, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/Rating.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/Rating.kt index 76fd8f3..055a5d0 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/Rating.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/Rating.kt @@ -11,6 +11,20 @@ class Rating( fun builder(): RatingBuilder { return RatingBuilder() } + + fun getRoadType(sum: Double): RoadType { + if (sum in 0.0..2.0) { + return RoadType.MUD_ROAD + } else if (sum in 2.1..4.0) { + return RoadType.DIRT_ROAD + } else if (sum in 4.1..6.0) { + return RoadType.GRASS_ROAD + } else if (sum in 6.1..8.0) { + return RoadType.FLOWER_ROAD + } else { + return RoadType.FULL_OF_FLOWER_ROAD + } + } } val sum: Double @@ -22,18 +36,8 @@ class Rating( if (it >= 10.0) 10.0 else it } } - - fun getRoadType(): RoadType { - if (sum in 0.0..2.0) { - return RoadType.MUD_ROAD - } else if (sum in 2.1..4.0) { - return RoadType.DIRT_ROAD - } else if (sum in 4.1..6.0) { - return RoadType.GRASS_ROAD - } else if (sum in 6.1..8.0) { - return RoadType.FLOWER_ROAD - } else { - return RoadType.FULL_OF_FLOWER_ROAD + val roadType: RoadType + get() { + return getRoadType(sum) } - } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt index b7acba6..eaa2715 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailEntity.kt @@ -3,66 +3,20 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.entity import jakarta.persistence.Column import jakarta.persistence.Entity import jakarta.persistence.Id -import kr.nagaza.nagazaserver.domain.model.CafeRoomReviewDetail @Entity(name = "cafe_room_review_det") class CafeRoomReviewDetailEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "user_cnt") - val userCnt: Int?, - + val userCnt: Int, @Column(name = "is_cleared") - val isCleared: Boolean?, - + val isCleared: Boolean, @Column(name = "is_life_theme") - val isLifeTheme: Boolean?, - + val isLifeTheme: Boolean, @Column(name = "used_hint_cnt") - val usedHintCnt: Int?, - - @Column(name = "difficulty_point") - val difficultyPoint: Int?, - - @Column(name = "activity_point") - val activityPoint: Int?, - - @Column(name = "interior_point") - val interiorPoint: Int?, - - @Column(name = "production_point") - val productionPoint: Int?, - - @Column(name = "device_ratio") - val deviceRatio: Double?, -) { - fun toModel() = CafeRoomReviewDetail( - reviewId = reviewId, - userCnt = userCnt, - isCleared = isCleared, - isLifeTheme = isLifeTheme, - usedHintCnt = usedHintCnt, - difficultyPoint = difficultyPoint, - activityPoint = activityPoint, - interiorPoint = interiorPoint, - productionPoint = productionPoint, - deviceRatio = deviceRatio, - ) - - companion object { - fun fromModel(model: CafeRoomReviewDetail) = CafeRoomReviewDetailEntity( - reviewId = model.reviewId, - userCnt = model.userCnt, - isCleared = model.isCleared, - isLifeTheme = model.isLifeTheme, - usedHintCnt = model.usedHintCnt, - difficultyPoint = model.difficultyPoint, - activityPoint = model.activityPoint, - interiorPoint = model.interiorPoint, - productionPoint = model.productionPoint, - deviceRatio = model.deviceRatio, - ) - } -} + val usedHintCnt: Int, + @Column(name = "content") + val content: String, +) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailOptEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailOptEntity.kt deleted file mode 100644 index 26fcbe3..0000000 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewDetailOptEntity.kt +++ /dev/null @@ -1,18 +0,0 @@ -package kr.nagaza.nagazaserver.infrastructure.jpa.entity - -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.Id - -@Entity(name = "cafe_room_review_det_opt") -class CafeRoomReviewDetailOptEntity( - @Id - @Column(name = "review_id") - val reviewId: String, - - @Column(name = "option_type") - val optionType: String, - - @Column(name = "option_value") - val optionValue: Boolean, -) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt index 802d85a..ab7b421 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewEntity.kt @@ -1,46 +1,23 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.entity import jakarta.persistence.* -import kr.nagaza.nagazaserver.domain.model.CafeRoomReview +import java.util.* @Entity(name = "cafe_room_review") class CafeRoomReviewEntity( @Id @Column(name = "review_id") val reviewId: String, - @Column(name = "room_id") val roomId: String, - @Column(name = "user_id") val userId: String, - - @Column(name = "content") - val content: String, - @OneToOne @PrimaryKeyJoinColumn val detail: CafeRoomReviewDetailEntity, - @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "review_id") - val reviewOpts: MutableSet = mutableSetOf(), -) { - fun toModel() = CafeRoomReview( - reviewId = reviewId, - roomId = roomId, - userId = userId, - content = content, - detail = detail.toModel(), - ) - - companion object { - fun fromModel(model: CafeRoomReview) = CafeRoomReviewEntity( - reviewId = model.reviewId, - roomId = model.roomId, - userId = model.userId, - content = model.content, - detail = CafeRoomReviewDetailEntity.fromModel(model.detail), - ) - } -} + val ratingFields: List = listOf(), + @Column(name = "created_at") + val createdAt: Date, +) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt new file mode 100644 index 0000000..52d1e02 --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomReviewRatingFieldEntity.kt @@ -0,0 +1,19 @@ +package kr.nagaza.nagazaserver.infrastructure.jpa.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Id +import kr.nagaza.nagazaserver.domain.model.rating.field.RatingFieldType + +@Entity(name = "cafe_room_review_rating_field") +class CafeRoomReviewRatingFieldEntity( + @Id + @Column(name = "rating_field_id") + val ratingFieldId: String, + @Column(name = "review_id") + val reviewId: String, + @Column(name = "type") + val fieldType: RatingFieldType, + @Column(name = "value") + val value: Int, +) 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 5c38fa1..18fa3a0 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 @@ -1,6 +1,9 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.repository import kr.nagaza.nagazaserver.domain.model.CafeRoomReview +import kr.nagaza.nagazaserver.domain.model.CafeRoomReviewDetail +import kr.nagaza.nagazaserver.domain.model.rating.Rating +import kr.nagaza.nagazaserver.domain.model.rating.field.RatingField import kr.nagaza.nagazaserver.domain.repository.CafeRoomReviewRepository import org.springframework.stereotype.Repository @@ -9,14 +12,43 @@ class CafeRoomReviewRepositoryImpl( private val cafeRoomReviewRepository: JpaCafeRoomReviewRepository, ) : CafeRoomReviewRepository { override fun getAllByUserId(userId: String): List { - return cafeRoomReviewRepository - .findAllByUserId(userId) - .map { it.toModel() } + throw NotImplementedError() } override fun getAllByRoomId(roomId: String): List { - return cafeRoomReviewRepository - .findAllByRoomId(roomId) - .map { it.toModel() } + val entity = + cafeRoomReviewRepository + .findAllByRoomId(roomId) + + println(entity) + println(entity.size) + + return entity.map { + val rating = Rating.builder() + it.ratingFields.forEach { field -> + rating.addRating( + RatingField( + field.fieldType, + field.value, + ), + ) + } + + CafeRoomReview( + reviewId = it.reviewId, + roomId = it.roomId, + userId = it.userId, + detail = + CafeRoomReviewDetail( + reviewId = it.reviewId, + userCnt = it.detail.userCnt, + isCleared = it.detail.isCleared, + usedHintCnt = it.detail.usedHintCnt, + content = it.detail.content, + ), + rating = rating.build(), + createdAt = it.createdAt, + ) + } } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomReviewApi.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomReviewApi.kt index 858b6af..04cfca7 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomReviewApi.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomReviewApi.kt @@ -2,7 +2,7 @@ package kr.nagaza.nagazaserver.presenter.restapi.api import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag -import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomReviewResponse +import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomReviewListResponse import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping @@ -17,5 +17,5 @@ interface CafeRoomReviewApi { fun getReviews( @PathVariable cafeId: String, @PathVariable roomId: String, - ): List + ): CafeRoomReviewListResponse } 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 8bb798c..4a5d328 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,17 +1,48 @@ package kr.nagaza.nagazaserver.presenter.restapi.controller +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 org.springframework.stereotype.Controller @Controller class CafeRoomReviewController( private val cafeRoomReviewService: CafeRoomReviewService, ) : CafeRoomReviewApi { - override fun getReviews(cafeId: String, roomId: String): List { - return cafeRoomReviewService.getAllByRoomId( - roomId = roomId, - ).map(CafeRoomReviewResponse::fromModel) + override fun getReviews( + cafeId: String, + roomId: String, + ): CafeRoomReviewListResponse { + val reviewList = + cafeRoomReviewService.getAllByRoomId( + roomId = roomId, + ) + + return CafeRoomReviewListResponse( + 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, + ) + }, + ) } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/MeController.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/MeController.kt index aec7e0f..5a37416 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/MeController.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/MeController.kt @@ -15,27 +15,24 @@ class MeController( private val userService: UserService, private val cafeRoomReviewService: CafeRoomReviewService, ) : MeApi { - override fun getMe( - userId: String, - ): MeResponse { + override fun getMe(userId: String): MeResponse { val me = userService.getUserInfo(userId) return me.let(MeResponse::fromModel) } override fun getMyReviews(userId: String): List { - return cafeRoomReviewService - .getAllByUserId(userId) - .map(CafeRoomReviewResponse::fromModel) + throw NotImplementedError() } override fun updateNickname( userId: String, request: UpdateNicknameRequest, ): MeResponse { - val result = userService.updateNickName( - userId = userId, - nickname = request.nickname, - ) + val result = + userService.updateNickName( + userId = userId, + nickname = request.nickname, + ) return result.let(MeResponse::fromModel) } @@ -43,10 +40,11 @@ class MeController( userId: String, request: UpdateProfileImageUrlRequest, ): MeResponse { - val result = userService.updateProfileImageUrl( - userId = userId, - profileImageUrl = request.profileImageUrl, - ) + val result = + userService.updateProfileImageUrl( + userId = userId, + profileImageUrl = request.profileImageUrl, + ) return result.let(MeResponse::fromModel) } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewListResponse.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewListResponse.kt new file mode 100644 index 0000000..5e8fbfd --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewListResponse.kt @@ -0,0 +1,12 @@ +package kr.nagaza.nagazaserver.presenter.restapi.dto.response + +import io.swagger.v3.oas.annotations.media.Schema +import kr.nagaza.nagazaserver.domain.model.rating.RoadType + +@Schema(description = "카페 방 리뷰 응답") +data class CafeRoomReviewListResponse( + val reviewCount: Int, + val rating: Double, + val roadType: RoadType, + val reviewList: List, +) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewResponse.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewResponse.kt index 587e1a5..ad2337e 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewResponse.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomReviewResponse.kt @@ -1,16 +1,16 @@ package kr.nagaza.nagazaserver.presenter.restapi.dto.response import io.swagger.v3.oas.annotations.media.Schema -import kr.nagaza.nagazaserver.domain.model.CafeRoomReview +import kr.nagaza.nagazaserver.domain.model.rating.RoadType +import java.util.* -@Schema(description = "카페 방 리뷰 응답") +@Schema() data class CafeRoomReviewResponse( - @Schema(description = "리뷰 아이디", example = "01HDNFJHCNS5E2W35YTB030TJ8") val reviewId: String, -) { - companion object { - fun fromModel(model: CafeRoomReview) = CafeRoomReviewResponse( - reviewId = model.reviewId, - ) - } -} + val userId: String, + val fields: List, + val rating: Double, + val roadType: RoadType, + val createdAt: Date, + val content: String?, +) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/RatingFieldResponse.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/RatingFieldResponse.kt new file mode 100644 index 0000000..5fa677e --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/RatingFieldResponse.kt @@ -0,0 +1,10 @@ +package kr.nagaza.nagazaserver.presenter.restapi.dto.response + +import io.swagger.v3.oas.annotations.media.Schema +import kr.nagaza.nagazaserver.domain.model.rating.field.RatingFieldType + +@Schema() +data class RatingFieldResponse( + val ratingFieldType: RatingFieldType, + val value: Int, +) diff --git a/src/main/resources/application-local.yaml b/src/main/resources/application-local.yaml index 320ef35..2f7a077 100644 --- a/src/main/resources/application-local.yaml +++ b/src/main/resources/application-local.yaml @@ -1,6 +1,8 @@ spring: jpa: show-sql: true + hibernate: + ddl-auto: update flyway: enabled: false baseline-on-migrate: false