diff --git a/src/main/java/com/nexters/goalpanzi/application/member/MemberService.java b/src/main/java/com/nexters/goalpanzi/application/member/MemberService.java index a07a6a98..294f22d5 100644 --- a/src/main/java/com/nexters/goalpanzi/application/member/MemberService.java +++ b/src/main/java/com/nexters/goalpanzi/application/member/MemberService.java @@ -28,10 +28,12 @@ public ProfileResponse getMember(final Long memberId) { @Transactional public void updateProfile(final UpdateProfileCommand request) { - validateNickname(request.nickname()); + request.nickname().ifPresent(this::validateNickname); + Member member = memberRepository.getMember(request.memberId()); - member.updateProfile(request.nickname(), request.characterType()); + request.nickname().ifPresent(member::updateNickname); + request.characterType().ifPresent(member::updateCharacterType); } private void validateNickname(final String nickname) { diff --git a/src/main/java/com/nexters/goalpanzi/application/member/dto/request/UpdateProfileCommand.java b/src/main/java/com/nexters/goalpanzi/application/member/dto/request/UpdateProfileCommand.java index b2ac95bf..04d17b76 100644 --- a/src/main/java/com/nexters/goalpanzi/application/member/dto/request/UpdateProfileCommand.java +++ b/src/main/java/com/nexters/goalpanzi/application/member/dto/request/UpdateProfileCommand.java @@ -2,9 +2,11 @@ import com.nexters.goalpanzi.domain.member.CharacterType; +import java.util.Optional; + public record UpdateProfileCommand( Long memberId, - String nickname, - CharacterType characterType + Optional nickname, + Optional characterType ) { } \ No newline at end of file diff --git a/src/main/java/com/nexters/goalpanzi/domain/member/Member.java b/src/main/java/com/nexters/goalpanzi/domain/member/Member.java index 6677bb58..0ab7ad1f 100644 --- a/src/main/java/com/nexters/goalpanzi/domain/member/Member.java +++ b/src/main/java/com/nexters/goalpanzi/domain/member/Member.java @@ -63,13 +63,12 @@ public Boolean isProfileSet() { return (characterType != null) && (nickname != null); } - public void updateProfile(final String nickname, final CharacterType characterType) { - if (nickname != null) { - this.nickname = nickname; - } - if (characterType != null) { - this.characterType = characterType; - } + public void updateNickname(final String nickname) { + this.nickname = nickname; + } + + public void updateCharacterType(final CharacterType characterType) { + this.characterType = characterType; } @Override diff --git a/src/main/java/com/nexters/goalpanzi/domain/mission/MemberRanks.java b/src/main/java/com/nexters/goalpanzi/domain/mission/MemberRanks.java index eabba6b8..233146fb 100644 --- a/src/main/java/com/nexters/goalpanzi/domain/mission/MemberRanks.java +++ b/src/main/java/com/nexters/goalpanzi/domain/mission/MemberRanks.java @@ -1,18 +1,21 @@ package com.nexters.goalpanzi.domain.mission; import com.nexters.goalpanzi.domain.member.Member; -import lombok.RequiredArgsConstructor; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; import java.util.Objects; -@RequiredArgsConstructor public class MemberRanks { private final List memberRanks; + private MemberRanks(final List memberRanks) { + this.memberRanks = memberRanks; + } + public static MemberRanks from(final List missionMembers) { List sortedMissionMembers = sortedMembersByVerificationCountDesc(missionMembers); @@ -29,7 +32,7 @@ public static MemberRanks from(final List missionMembers) { previousVerificationCount = missionMember.getVerificationCount(); } - return new MemberRanks(memberRanks); + return new MemberRanks(Collections.unmodifiableList(memberRanks)); } private static List sortedMembersByVerificationCountDesc(final List missionMembers) { diff --git a/src/main/java/com/nexters/goalpanzi/presentation/member/dto/UpdateProfileRequest.java b/src/main/java/com/nexters/goalpanzi/presentation/member/dto/UpdateProfileRequest.java index 86c75b3c..3b71dd07 100644 --- a/src/main/java/com/nexters/goalpanzi/presentation/member/dto/UpdateProfileRequest.java +++ b/src/main/java/com/nexters/goalpanzi/presentation/member/dto/UpdateProfileRequest.java @@ -4,13 +4,19 @@ import com.nexters.goalpanzi.domain.member.CharacterType; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.Optional; + public record UpdateProfileRequest( @Schema(description = "닉네임", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - String nickname, + Optional nickname, @Schema(description = "장기말 타입", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - CharacterType characterType + Optional characterType ) { + public UpdateProfileRequest(final String nickname, final CharacterType characterType) { + this(Optional.ofNullable(nickname), Optional.ofNullable(characterType)); + } + public UpdateProfileCommand toServiceDto(Long memberId) { return new UpdateProfileCommand( memberId, diff --git a/src/test/java/com/nexters/goalpanzi/domain/member/MemberTest.java b/src/test/java/com/nexters/goalpanzi/domain/member/MemberTest.java index 2713c0d2..1fe9e8ba 100644 --- a/src/test/java/com/nexters/goalpanzi/domain/member/MemberTest.java +++ b/src/test/java/com/nexters/goalpanzi/domain/member/MemberTest.java @@ -4,54 +4,39 @@ import static com.nexters.goalpanzi.fixture.MemberFixture.*; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; class MemberTest { @Test - void 프로필_생성이_가능하다() { + void 닉네임_설정이_가능하다() { Member member = Member.socialLogin(SOCIAL_ID, EMAIL_HOST, SocialType.APPLE); - member.updateProfile(NICKNAME_HOST, CharacterType.CAT); + member.updateNickname(NICKNAME_HOST); - assertAll( - () -> assertThat(member.isProfileSet()).isTrue(), - () -> assertThat(member.getNickname()).isEqualTo(NICKNAME_HOST), - () -> assertThat(member.getCharacterType()).isEqualTo(CharacterType.CAT) - ); + assertThat(member.getNickname()).isEqualTo(NICKNAME_HOST); } @Test - void 프로필_생성후_변경이_가능하다() { + void 장기말타입_설정이_가능하다() { Member member = Member.socialLogin(SOCIAL_ID, EMAIL_HOST, SocialType.APPLE); - member.updateProfile(NICKNAME_HOST, CharacterType.CAT); - member.updateProfile(NICKNAME_HOST, null); - - assertAll( - () -> assertThat(member.isProfileSet()).isTrue(), - () -> assertThat(member.getNickname()).isEqualTo(NICKNAME_HOST), - () -> assertThat(member.getCharacterType()).isEqualTo(CharacterType.CAT) - ); + member.updateCharacterType(CHARACTER_HOST); + + assertThat(member.getCharacterType()).isEqualTo(CHARACTER_HOST); } @Test - void 닉네임만_설정이_가능하다() { + void 닉네임과_장기말타입_전부_설정시_프로필_설정여부를_true로_반환한다(){ Member member = Member.socialLogin(SOCIAL_ID, EMAIL_HOST, SocialType.APPLE); - member.updateProfile(NICKNAME_HOST, null); + member.updateNickname(NICKNAME_HOST); + member.updateCharacterType(CHARACTER_HOST); - assertAll( - () -> assertThat(member.isProfileSet()).isFalse(), - () -> assertThat(member.getNickname()).isEqualTo(NICKNAME_HOST) - ); + assertThat(member.isProfileSet()).isTrue(); } @Test - void 캐릭터만_설정이_가능하다() { + void 닉네임과_장기말타입_중_하나라도_설정되지_않은경우_프로필_설정여부를_false로_반환한다(){ Member member = Member.socialLogin(SOCIAL_ID, EMAIL_HOST, SocialType.APPLE); - member.updateProfile(null, CharacterType.CAT); + member.updateNickname(NICKNAME_HOST); - assertAll( - () -> assertThat(member.isProfileSet()).isFalse(), - () -> assertThat(member.getCharacterType()).isEqualTo(CharacterType.CAT) - ); + assertThat(member.isProfileSet()).isFalse(); } } \ No newline at end of file