-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
137 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 8 additions & 10 deletions
18
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoomReview.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
package kr.nagaza.nagazaserver.domain.model | ||
|
||
import kr.nagaza.nagazaserver.domain.model.rating.Rating | ||
import java.util.* | ||
|
||
data class CafeRoomReview( | ||
val reviewId: String, | ||
val roomId: String, | ||
val userId: String, | ||
val content: String, | ||
val detail: CafeRoomReviewDetail, | ||
val rating: Rating, | ||
val createdAt: Date, | ||
) | ||
|
||
data class CafeRoomReviewDetail( | ||
val reviewId: String, | ||
val userCnt: Int?, | ||
val isCleared: Boolean?, | ||
val isLifeTheme: Boolean?, | ||
val usedHintCnt: Int?, | ||
val difficultyPoint: Int?, | ||
val activityPoint: Int?, | ||
val interiorPoint: Int?, | ||
val productionPoint: Int?, | ||
val deviceRatio: Double?, | ||
val userCnt: Int, | ||
val isCleared: Boolean, | ||
val usedHintCnt: Int, | ||
) |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/Rating.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating | ||
|
||
import kr.nagaza.nagazaserver.domain.model.rating.field.RatingField | ||
import kr.nagaza.nagazaserver.domain.model.rating.field.RatingFieldType | ||
import kr.nagaza.nagazaserver.domain.model.rating.field.getConstraint | ||
|
||
class Rating( | ||
val fields: Map<RatingFieldType, RatingField>, | ||
) { | ||
companion object { | ||
fun builder(): RatingBuilder { | ||
return RatingBuilder() | ||
} | ||
} | ||
|
||
val sum: Double | ||
get() { | ||
return fields | ||
.values.map { it.value * getConstraint(it.type).weight } | ||
.sum() | ||
.let { | ||
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 | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/RatingBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating | ||
|
||
import kr.nagaza.nagazaserver.domain.model.rating.field.RatingField | ||
import kr.nagaza.nagazaserver.domain.model.rating.field.RatingFieldType | ||
|
||
class RatingBuilder { | ||
private val fields: MutableMap<RatingFieldType, RatingField> = mutableMapOf() | ||
|
||
fun addRating(field: RatingField): RatingBuilder { | ||
fields[field.type] = field | ||
return this | ||
} | ||
|
||
fun build(): Rating { | ||
if (fields.size == RatingFieldType.values().size) { | ||
return Rating(fields) | ||
} else { | ||
throw Exception("Not all ratings are set") | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/RoadType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating | ||
|
||
enum class RoadType { | ||
MUD_ROAD, | ||
DIRT_ROAD, | ||
GRASS_ROAD, | ||
FLOWER_ROAD, | ||
FULL_OF_FLOWER_ROAD, | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/exception/RatingException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import kr.nagaza.nagazaserver.domain.exception.DomainException | ||
import kr.nagaza.nagazaserver.domain.exception.ErrorCode | ||
|
||
class InvalidRatingValueException : DomainException(ErrorCode.INVALID_RATING_VALUE) |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/field/Rating.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating.field | ||
|
||
val constraints: Map<RatingFieldType, RatingConstraint> = | ||
mapOf( | ||
RatingFieldType.EXPRESSION to RatingConstraint(1, 5, 0.765), | ||
RatingFieldType.LOCK to RatingConstraint(1, 9, 0.294), | ||
RatingFieldType.INTERIOR to RatingConstraint(1, 5, 0.412), | ||
RatingFieldType.ACTIVITY to RatingConstraint(1, 5, 0.235), | ||
RatingFieldType.DIFFICULTY to RatingConstraint(1, 5, 0.059), | ||
RatingFieldType.IS_IMPRESSED to RatingConstraint(0, 1, 1.0), | ||
) | ||
|
||
fun getConstraint(type: RatingFieldType): RatingConstraint { | ||
return constraints[type]!! | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/field/RatingConstraint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating.field | ||
|
||
data class RatingConstraint( | ||
val min: Int, | ||
val max: Int, | ||
val weight: Double, | ||
) { | ||
fun getValue(value: Int): Double { | ||
return value * weight | ||
} | ||
|
||
fun isInRange(value: Int): Boolean { | ||
return value in min..max | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/field/RatingField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating.field | ||
|
||
import InvalidRatingValueException | ||
|
||
data class RatingField( | ||
val type: RatingFieldType, | ||
val value: Int, | ||
) { | ||
init { | ||
if (!getConstraint(type).isInRange(value)) { | ||
throw InvalidRatingValueException() | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/kr/nagaza/nagazaserver/domain/model/rating/field/RatingFieldType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kr.nagaza.nagazaserver.domain.model.rating.field | ||
|
||
enum class RatingFieldType { | ||
EXPRESSION, | ||
LOCK, | ||
INTERIOR, | ||
ACTIVITY, | ||
DIFFICULTY, | ||
IS_IMPRESSED, | ||
} |