Skip to content

Commit 8dfda89

Browse files
authored
랭킹(rating) 올림 처리로 수정한다. (#115)
fix: ceil rating
1 parent 1b95323 commit 8dfda89

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

api/src/main/kotlin/com/gotchai/api/presentation/v1/user/response/UserRankingResponse.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.gotchai.domain.user.dto.result.GetUserRankingResult
44

55
data class UserRankingResponse(
66
val name: String,
7-
val rating: Double
7+
val rating: Int
88
) {
99
companion object {
1010
fun from(result: GetUserRankingResult) =

domain/src/main/kotlin/com/gotchai/domain/user/adapter/in/UserQueryService.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.gotchai.domain.user.exception.ProfileNotFoundException
77
import com.gotchai.domain.user.port.`in`.UserQueryUseCase
88
import com.gotchai.domain.user.port.out.ProfileQueryPort
99
import org.springframework.stereotype.Service
10+
import kotlin.math.ceil
1011

1112
@Service
1213
class UserQueryService(
@@ -24,8 +25,8 @@ class UserQueryService(
2425
private fun calculateUserRating(
2526
userId: Long,
2627
allHistories: List<ExamHistory>
27-
): Double {
28-
if (allHistories.isEmpty() || !allHistories.any { it.userId == userId }) return 100.0
28+
): Int {
29+
if (allHistories.isEmpty() || !allHistories.any { it.userId == userId }) return 100
2930

3031
val userScores =
3132
allHistories
@@ -36,10 +37,11 @@ class UserQueryService(
3637
if (totalQuizzes == 0) 0.0 else totalCorrect.toDouble() / totalQuizzes.toDouble()
3738
}
3839

39-
val userScore = userScores[userId] ?: return 100.0
40-
if (userScores.size == 1) return 0.0
40+
val userScore = userScores[userId] ?: return 100
41+
if (userScores.size == 1) return 0
4142

4243
val usersWithHigherScore = userScores.values.count { it > userScore }
43-
return (usersWithHigherScore.toDouble() / userScores.size.toDouble()) * 100
44+
val rating = (usersWithHigherScore.toDouble() / userScores.size.toDouble()) * 100
45+
return ceil(rating).toInt()
4446
}
4547
}

domain/src/main/kotlin/com/gotchai/domain/user/dto/result/GetUserRankingResult.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import com.gotchai.domain.user.entity.Profile
44

55
data class GetUserRankingResult(
66
val name: String,
7-
val rating: Double
7+
val rating: Int
88
) {
99
companion object {
1010
fun of(
1111
profile: Profile,
12-
rating: Double
12+
rating: Int
1313
) = GetUserRankingResult(
1414
name = profile.nickname,
1515
rating = rating

domain/src/testFixtures/kotlin/com/gotchai/domain/fixture/UserFixture.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fun createUserSocial(
5656

5757
fun createGetUserRankingResult(
5858
name: String = NICKNAME,
59-
rating: Double = 25.0
59+
rating: Int = 25
6060
): GetUserRankingResult =
6161
GetUserRankingResult(
6262
name = name,

0 commit comments

Comments
 (0)