diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt index 90f74eb..6065c5b 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/GroupFacade.kt @@ -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 ) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/model/response/GetGroupRanksResponse.kt b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/GetGroupRanksResponse.kt index 702521a..1083f42 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/model/response/GetGroupRanksResponse.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/GetGroupRanksResponse.kt @@ -2,7 +2,11 @@ package com.hero.alignlab.domain.group.model.response data class GetGroupRanksResponse( val groupId: Long, - val ranks: List + val ranks: List, + /** 크루 전체 평균 스코어 */ + val avgScore: Int?, + /** 내 평균 스코어 */ + val myScore: Int?, ) data class GetGroupRankResponse(