Skip to content

Commit

Permalink
imp: 디자인 가이드에 맞추어, 마이그룹 조회 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 3, 2024
1 parent 2590737 commit e3f561b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class GroupFacade(
.filterNot { groupUserScore -> groupUserScore.score == null }
.sortedBy { groupUserScore -> groupUserScore.score }

val userbyId = userInfoService.findAllByIds(groupUserScores.map { it.uid }).associateBy { it.id }
val userById = userInfoService.findAllByIds(groupUserScores.map { it.uid }).associateBy { it.id }

val rank = AtomicInteger(1)

Expand All @@ -239,7 +239,7 @@ class GroupFacade(
ranks = groupUserScores.mapNotNull { groupUserScore ->
GetGroupRankResponse(
groupUserId = groupUserScore.groupUserId,
name = userbyId[groupUserScore.uid]?.nickname ?: return@mapNotNull null,
name = userById[groupUserScore.uid]?.nickname ?: return@mapNotNull null,
rank = rank.getAndIncrement(),
score = groupUserScore.score ?: return@mapNotNull null,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package com.hero.alignlab.domain.group.application

import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.model.response.MyGroupResponse
import com.hero.alignlab.domain.user.application.UserInfoService
import org.springframework.stereotype.Service

@Service
class MyGroupService(
class MyGroupFacade(
private val groupService: GroupService,
private val groupUserService: GroupUserService,
private val userInfoService: UserInfoService,
) {
// TODO : 기획 확인후, 코드 변경
suspend fun getMyGroup(user: AuthUser): MyGroupResponse? {
val groupUser = groupUserService.findByUid(user.uid) ?: return null
val group = groupService.findByIdOrThrow(groupUser.groupId)
val groupUserCount = groupUserService.countAllByGroupId(groupUser.groupId)
val userInfo = userInfoService.findByIdOrThrow(group.ownerUid)

return MyGroupResponse.from(group)
return MyGroupResponse.of(group, groupUserCount.toInt(), userInfo.nickname)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ package com.hero.alignlab.domain.group.model.response
import com.hero.alignlab.domain.group.domain.Group

data class MyGroupResponse(
/** group id */
val id: Long,
/** 그룹명 */
val name: String,
/** 그룹 설명 */
val description: String?,
/** 그룹원 수 */
val userCount: Int,
/** 그룹 정원 */
val userCapacity: Int,
/** 그룹장 명 */
val ownerNickname: String,
) {
companion object {
fun from(group: Group): MyGroupResponse {
fun of(group: Group, userCount: Int, nickname: String): MyGroupResponse {
return MyGroupResponse(
id = group.id,
name = group.name,
description = group.description
description = group.description,
userCount = userCount,
userCapacity = group.userCapacity,
ownerNickname = nickname
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController
class GroupUserScoreResource(
private val groupFacade: GroupFacade,
) {
/** 내가 속한 그룹의 전체 랭킹을 조회할 수 있다 */
@Operation(summary = "바른 자세 랭킹")
@GetMapping("/api/v1/group-scores")
suspend fun getScores(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.hero.alignlab.domain.group.resource

import com.hero.alignlab.common.extension.wrapOk
import com.hero.alignlab.domain.auth.model.AuthUser
import com.hero.alignlab.domain.group.application.MyGroupService
import com.hero.alignlab.domain.group.application.MyGroupFacade
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.MediaType
Expand All @@ -14,12 +14,12 @@ import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping(produces = [MediaType.APPLICATION_JSON_VALUE])
class MyGroupResource(
private val myGroupService: MyGroupService,
private val myGroupFacade: MyGroupFacade,
) {
/** 그룹이 없는 경우, noContent로 반환 */
@Operation(summary = "마이 그룹 조회")
@GetMapping("/api/v1/groups/my-group")
suspend fun getMyGroup(
user: AuthUser
) = myGroupService.getMyGroup(user).wrapOk()
) = myGroupFacade.getMyGroup(user).wrapOk()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package com.hero.alignlab.domain.user.application

import com.hero.alignlab.common.encrypt.EncryptData
import com.hero.alignlab.common.encrypt.Encryptor
import com.hero.alignlab.domain.user.domain.vo.OAuthProvider
import com.hero.alignlab.domain.user.domain.UserInfo
import com.hero.alignlab.domain.user.domain.vo.OAuthProvider
import com.hero.alignlab.domain.user.infrastructure.UserInfoRepository
import com.hero.alignlab.domain.user.model.response.UserInfoResponse
import com.hero.alignlab.exception.ErrorCode
Expand All @@ -28,6 +28,17 @@ class UserInfoService(
return userInfoRepository.findByIdOrNull(id)
}

suspend fun findByIdOrThrow(id: Long): UserInfo {
return findByIdOrNull(id)
?: throw NotFoundException(ErrorCode.NOT_FOUND_USER_ERROR)
}

suspend fun findByIdOrNull(id: Long): UserInfo? {
return withContext(Dispatchers.IO) {
userInfoRepository.findByIdOrNull(id)
}
}

fun saveSync(userInfo: UserInfo): UserInfo {
return userInfoRepository.save(userInfo)
}
Expand Down

0 comments on commit e3f561b

Please sign in to comment.