From e63cc25c76f40f4dc4311a0caa914ba3ef7152bf Mon Sep 17 00:00:00 2001 From: Park - Jeonghwan <990706leo@gmail.com> Date: Tue, 13 Aug 2024 19:38:06 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B7=B8=EB=A3=B9=20=ED=83=88=ED=87=B4?= =?UTF-8?q?=EB=A5=BC=20=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/member/controller/MemberController.kt | 2 +- .../server/member/service/MemberAccountService.kt | 4 ++-- .../snackgame/server/member/service/dto/GroupRequest.kt | 2 -- .../server/member/service/MemberAccountServiceTest.kt | 8 ++++++++ 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/snackgame/server/member/controller/MemberController.kt b/src/main/java/com/snackgame/server/member/controller/MemberController.kt index 2e0dafa..4bccd23 100644 --- a/src/main/java/com/snackgame/server/member/controller/MemberController.kt +++ b/src/main/java/com/snackgame/server/member/controller/MemberController.kt @@ -65,7 +65,7 @@ class MemberController( @PutMapping("/members/me/group") fun changeGroup( @Authenticated member: Member, - @Valid @RequestBody groupRequest: GroupRequest + @RequestBody groupRequest: GroupRequest ): MemberDetailsResponse { memberAccountService.changeGroupNameOf(member.id, groupRequest.group) return MemberDetailsResponse.of(member) diff --git a/src/main/java/com/snackgame/server/member/service/MemberAccountService.kt b/src/main/java/com/snackgame/server/member/service/MemberAccountService.kt index 69bfdb7..53a5c14 100644 --- a/src/main/java/com/snackgame/server/member/service/MemberAccountService.kt +++ b/src/main/java/com/snackgame/server/member/service/MemberAccountService.kt @@ -64,9 +64,9 @@ class MemberAccountService( } @Transactional - fun changeGroupNameOf(memberId: Long, groupName: String) { + fun changeGroupNameOf(memberId: Long, groupName: String?) { val member = members.getBy(memberId) - val group = groupService.createIfNotExists(groupName) + val group = groupName?.let { groupService.createIfNotExists(it) } member.changeGroupTo(group) } diff --git a/src/main/java/com/snackgame/server/member/service/dto/GroupRequest.kt b/src/main/java/com/snackgame/server/member/service/dto/GroupRequest.kt index 3e84c96..beba0d2 100644 --- a/src/main/java/com/snackgame/server/member/service/dto/GroupRequest.kt +++ b/src/main/java/com/snackgame/server/member/service/dto/GroupRequest.kt @@ -1,10 +1,8 @@ package com.snackgame.server.member.service.dto import com.fasterxml.jackson.annotation.JsonCreator -import javax.validation.constraints.NotBlank data class GroupRequest @JsonCreator constructor( - @field:NotBlank(message = "그룹 이름은 공백일 수 없습니다") val group: String ) diff --git a/src/test/java/com/snackgame/server/member/service/MemberAccountServiceTest.kt b/src/test/java/com/snackgame/server/member/service/MemberAccountServiceTest.kt index 289f2e8..24855c0 100644 --- a/src/test/java/com/snackgame/server/member/service/MemberAccountServiceTest.kt +++ b/src/test/java/com/snackgame/server/member/service/MemberAccountServiceTest.kt @@ -100,6 +100,14 @@ internal class MemberAccountServiceTest { .isEqualTo("홍천고") } + @Test + fun `그룹 이름이 null이면 그룹을 탈퇴한다`() { + val member = memberAccountService.createWith(땡칠().getNameAsString(), 땡칠().group!!.name) + memberAccountService.changeGroupNameOf(member.id, null) + + assertThat(memberAccountService.getBy(member.id).group).isNull() + } + @Test fun `사용자를 id로 찾는다`() { val created = memberAccountService.createWith(땡칠().getNameAsString(), 땡칠().group!!.name)