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)