Skip to content

Commit

Permalink
fix: 그룹 상세 조회시, 랭킹 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 3, 2024
1 parent fcedcb6 commit 2590737
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,43 @@ class GroupFacade(
return parZip(
{ groupService.findByIdOrThrow(groupId) },
{ groupUserService.existsByGroupIdAndUid(groupId, user.uid) },
) { group, joinedGroup ->
if (!joinedGroup) {
throw NotFoundException(ErrorCode.NOT_FOUND_GROUP_ERROR)
{
groupUserScoreService.findAllByGroupId(groupId)
.filterNot { groupUserScore -> groupUserScore.score == null }
.sortedBy { groupUserScore -> groupUserScore.score }
.take(5)
}

) { group, joinedGroup, groupUserScore ->
GetGroupResponse.from(group).run {
when (group.ownerUid == user.uid) {
true -> this
false -> this.copy(joinCode = null)
}
}.run {
when (joinedGroup) {
true -> {
val uids = groupUserScore.map { it.uid }

val userInfo = userInfoService.findAllByIds(uids).associateBy { userInfo -> userInfo.id }
val groupUser = groupUserService.findAllByGroupIdAndUids(groupId, uids)
.associateBy { groupUser -> groupUser.uid }

val rank = AtomicInteger(1)

val ranks = groupUserScore.mapNotNull { score ->
GetGroupRankResponse(
groupUserId = groupUser[score.uid]?.id ?: return@mapNotNull null,
name = userInfo[score.uid]?.nickname ?: return@mapNotNull null,
rank = rank.getAndIncrement(),
score = score.score ?: 0,
)
}

this.copy(ranks = ranks)
}

false -> this
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ data class GetGroupResponse(
val userCount: Int,
/** 그룹 정원 */
val userCapacity: Int,
val ranks: List<GetGroupRankResponse>? = null
) {
companion object {
fun from(group: Group): GetGroupResponse {
return GetGroupResponse(
group.id,
group.name,
group.description,
group.ownerUid,
group.isHidden,
group.joinCode,
group.userCount,
group.userCapacity
id = group.id,
name = group.name,
description = group.description,
ownerUid = group.ownerUid,
isHidden = group.isHidden,
joinCode = group.joinCode,
userCount = group.userCount,
userCapacity = group.userCapacity
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class GroupResource(
private val groupFacade: GroupFacade,
) {
/**
* - 속해 있는 그룹의 정보를 조회할 수 있다.
* 그룹 상세 조회
* - 그룹장의 경우, joinCode를 조회할 수 있다.(그룹원은 조회 불가.)
* - 그룹에 속해있는 경우에만, 랭킹 정보를 확인 가능하다.
*/
@Operation(summary = "그룹 조회")
@GetMapping("/api/v1/groups/{id}")
Expand Down

0 comments on commit 2590737

Please sign in to comment.