Skip to content

Commit

Permalink
fix: 그룹 전체 평균 스코어 및 내 스코어 정보 제공
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 27, 2024
1 parent daf3efc commit 237855e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,22 @@ class GroupFacade(
val userById = userInfoService.findAllByIds(groupUserScores.map { it.uid }).associateBy { it.id }

val rank = AtomicInteger(1)
val ranks = groupUserScores.mapNotNull { groupUserScore ->
GetGroupRankResponse(
groupUserId = groupUserScore.groupUserId,
name = userById[groupUserScore.uid]?.nickname ?: return@mapNotNull null,
rank = rank.getAndIncrement(),
score = groupUserScore.score ?: return@mapNotNull null,
)
}
val avgGroupUserScore = (ranks.sumOf { it.score } / ranks.size)
val myScore = ranks.firstOrNull { it.groupUserId == groupUser.id }?.score

return GetGroupRanksResponse(
groupId = groupUser.groupId,
ranks = groupUserScores.mapNotNull { groupUserScore ->
GetGroupRankResponse(
groupUserId = groupUserScore.groupUserId,
name = userById[groupUserScore.uid]?.nickname ?: return@mapNotNull null,
rank = rank.getAndIncrement(),
score = groupUserScore.score ?: return@mapNotNull null,
)
}
ranks = ranks,
avgScore = avgGroupUserScore,
myScore = myScore
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.hero.alignlab.domain.group.model.response

data class GetGroupRanksResponse(
val groupId: Long,
val ranks: List<GetGroupRankResponse>
val ranks: List<GetGroupRankResponse>,
/** 크루 전체 평균 스코어 */
val avgScore: Int?,
/** 내 평균 스코어 */
val myScore: Int?,
)

data class GetGroupRankResponse(
Expand Down

0 comments on commit 237855e

Please sign in to comment.