File tree Expand file tree Collapse file tree 4 files changed +11
-9
lines changed
api/src/main/kotlin/com/gotchai/api/presentation/v1/user/response
main/kotlin/com/gotchai/domain/user
testFixtures/kotlin/com/gotchai/domain/fixture Expand file tree Collapse file tree 4 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import com.gotchai.domain.user.dto.result.GetUserRankingResult
44
55data class UserRankingResponse (
66 val name : String ,
7- val rating : Double
7+ val rating : Int
88) {
99 companion object {
1010 fun from (result : GetUserRankingResult ) =
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import com.gotchai.domain.user.exception.ProfileNotFoundException
77import com.gotchai.domain.user.port.`in`.UserQueryUseCase
88import com.gotchai.domain.user.port.out.ProfileQueryPort
99import org.springframework.stereotype.Service
10+ import kotlin.math.ceil
1011
1112@Service
1213class 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}
Original file line number Diff line number Diff line change @@ -4,12 +4,12 @@ import com.gotchai.domain.user.entity.Profile
44
55data 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
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ fun createUserSocial(
5656
5757fun createGetUserRankingResult (
5858 name : String = NICKNAME ,
59- rating : Double = 25.0
59+ rating : Int = 25
6060): GetUserRankingResult =
6161 GetUserRankingResult (
6262 name = name,
You can’t perform that action at this time.
0 commit comments