Skip to content

Commit

Permalink
feat: 변경된 리뷰 서비스 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed Jan 30, 2024
1 parent a84691d commit 2a4e702
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ data class CafeRoomReviewDetail(
val userCnt: Int,
val isCleared: Boolean,
val usedHintCnt: Int,
val content: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<CafeRoomReviewDetailOptEntity> = 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<CafeRoomReviewRatingFieldEntity> = listOf(),
@Column(name = "created_at")
val createdAt: Date,
)
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -9,14 +12,43 @@ class CafeRoomReviewRepositoryImpl(
private val cafeRoomReviewRepository: JpaCafeRoomReviewRepository,
) : CafeRoomReviewRepository {
override fun getAllByUserId(userId: String): List<CafeRoomReview> {
return cafeRoomReviewRepository
.findAllByUserId(userId)
.map { it.toModel() }
throw NotImplementedError()
}

override fun getAllByRoomId(roomId: String): List<CafeRoomReview> {
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,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -17,5 +17,5 @@ interface CafeRoomReviewApi {
fun getReviews(
@PathVariable cafeId: String,
@PathVariable roomId: String,
): List<CafeRoomReviewResponse>
): CafeRoomReviewListResponse
}
Original file line number Diff line number Diff line change
@@ -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<CafeRoomReviewResponse> {
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,
)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,36 @@ 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<CafeRoomReviewResponse> {
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)
}

override fun updateProfileImage(
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)
}

Expand Down
Loading

0 comments on commit 2a4e702

Please sign in to comment.