Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

그룹 탈퇴를 할 수 있다. #167

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading