From 2ab3d81ec1f6645ea27072109f994ea59dc17886 Mon Sep 17 00:00:00 2001 From: gidskql6671 Date: Wed, 29 May 2024 22:51:13 +0900 Subject: [PATCH] =?UTF-8?q?GroupDetailDto=EB=A5=BC=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=ED=95=98=EB=8A=94=20API=EC=9D=98=20=EC=9D=91=EB=8B=B5=EC=97=90?= =?UTF-8?q?=20isMember=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../onedayonebaek/group/dto/GroupDetailDto.kt | 22 +++++++++++-------- .../group/service/GroupService.kt | 15 +++++++------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/back/src/main/kotlin/knu/dong/onedayonebaek/group/dto/GroupDetailDto.kt b/back/src/main/kotlin/knu/dong/onedayonebaek/group/dto/GroupDetailDto.kt index 9f1f2ec..950c238 100644 --- a/back/src/main/kotlin/knu/dong/onedayonebaek/group/dto/GroupDetailDto.kt +++ b/back/src/main/kotlin/knu/dong/onedayonebaek/group/dto/GroupDetailDto.kt @@ -25,6 +25,9 @@ data class GroupDetailDto( @Schema(description = "문제를 풀지 않은 날 매겨지는 벌금", nullable = false, example = "1000") val fine: Int, + @Schema(description = "해당 그룹에 속해있는지 여부", nullable = false, example = "false") + val isMember: Boolean, + @Schema(description = "그룹에 속한 유저", nullable = false) val users: List, @@ -32,15 +35,16 @@ data class GroupDetailDto( val owner: UserDto ) -fun Group.toGroupDetailDto() = +fun Group.toGroupDetailDto(isMember: Boolean) = GroupDetailDto( - id!!, - name, - isPrivate, - inviteCode, - goalSolveCount, - fine, - users.map { it.user.toUserDto() }, - owner.toUserDto() + id = id!!, + name = name, + isPrivate = isPrivate, + inviteCode = inviteCode, + goalSolveCount = goalSolveCount, + fine = fine, + isMember = isMember, + users = users.map { it.user.toUserDto() }, + owner = owner.toUserDto() ) diff --git a/back/src/main/kotlin/knu/dong/onedayonebaek/group/service/GroupService.kt b/back/src/main/kotlin/knu/dong/onedayonebaek/group/service/GroupService.kt index f0d860e..b3f9c2c 100644 --- a/back/src/main/kotlin/knu/dong/onedayonebaek/group/service/GroupService.kt +++ b/back/src/main/kotlin/knu/dong/onedayonebaek/group/service/GroupService.kt @@ -43,9 +43,10 @@ class GroupService ( fun getGroupDetail(user: User, groupId: Long): GroupDetailDto { val group = groupRepository.findById(groupId).orElseThrow{ NotFoundException(message = "해당 그룹이 없습니다.") } + val isMember = containGroupRepository.existsByGroupAndUser(group, user) - if (!group.isPrivate || containGroupRepository.existsByGroupAndUser(group, user)) { - return group.toGroupDetailDto() + if (!group.isPrivate || isMember) { + return group.toGroupDetailDto(isMember = isMember) } throw ForbiddenException(message = "해당 비밀 그룹에 속해있지 않습니다.") @@ -71,7 +72,7 @@ class GroupService ( createdGroup.users.add(createdCG) - return group.toGroupDetailDto() + return group.toGroupDetailDto(isMember = true) } @Transactional @@ -95,7 +96,7 @@ class GroupService ( val updatedGroup = groupRepository.save(existingGroup) - return updatedGroup.toGroupDetailDto() + return updatedGroup.toGroupDetailDto(isMember = true) } @Transactional @@ -109,7 +110,7 @@ class GroupService ( if (!group.isPrivate) { containGroupRepository.save(ContainGroup(user, group)) - return group.toGroupDetailDto() + return group.toGroupDetailDto(isMember = true) } if (password == null) { @@ -121,7 +122,7 @@ class GroupService ( if (isCorrectPW) { containGroupRepository.save(ContainGroup(user, group)) - return group.toGroupDetailDto() + return group.toGroupDetailDto(isMember = true) } throw ConflictException("incorrect_password", "비밀번호가 다릅니다.") @@ -139,7 +140,7 @@ class GroupService ( containGroupRepository.save(ContainGroup(user, group)) - return group.toGroupDetailDto() + return group.toGroupDetailDto(isMember = true) } @Transactional