From e3f561ba387086426ef64fbec5a55f58f9113334 Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Wed, 4 Sep 2024 00:34:30 +0900 Subject: [PATCH] =?UTF-8?q?imp:=20=EB=94=94=EC=9E=90=EC=9D=B8=20=EA=B0=80?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=EC=97=90=20=EB=A7=9E=EC=B6=94=EC=96=B4,=20?= =?UTF-8?q?=EB=A7=88=EC=9D=B4=EA=B7=B8=EB=A3=B9=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/group/application/GroupFacade.kt | 4 ++-- .../{MyGroupService.kt => MyGroupFacade.kt} | 9 +++++++-- .../group/model/response/MyGroupResponse.kt | 16 ++++++++++++++-- .../group/resource/GroupUserScoreResource.kt | 1 + .../domain/group/resource/MyGroupResource.kt | 6 +++--- .../domain/user/application/UserInfoService.kt | 13 ++++++++++++- 6 files changed, 39 insertions(+), 10 deletions(-) rename src/main/kotlin/com/hero/alignlab/domain/group/application/{MyGroupService.kt => MyGroupFacade.kt} (56%) 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 195aa08..b58bb54 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 @@ -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) @@ -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, ) diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt b/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupFacade.kt similarity index 56% rename from src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt rename to src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupFacade.kt index ab5af7b..b6d85ed 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/application/MyGroupFacade.kt @@ -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) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt index 12b06b2..bb303c2 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/model/response/MyGroupResponse.kt @@ -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 ) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupUserScoreResource.kt b/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupUserScoreResource.kt index e65797b..73e9da3 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupUserScoreResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/resource/GroupUserScoreResource.kt @@ -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( diff --git a/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt b/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt index c9d6436..8249405 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/group/resource/MyGroupResource.kt @@ -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 @@ -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() } diff --git a/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt b/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt index 209dbf2..fdabeb4 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/user/application/UserInfoService.kt @@ -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 @@ -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) }