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

feat: 프로필 not null 필드만 업데이트하도록 수정 #54

Merged
merged 2 commits 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 @@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 👍


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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> nickname,
Optional<CharacterType> characterType
) {
}
13 changes: 6 additions & 7 deletions src/main/java/com/nexters/goalpanzi/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MemberRank> memberRanks;

private MemberRanks(final List<MemberRank> memberRanks) {
this.memberRanks = memberRanks;
}

public static MemberRanks from(final List<MissionMember> missionMembers) {
List<MissionMember> sortedMissionMembers = sortedMembersByVerificationCountDesc(missionMembers);

Expand All @@ -29,7 +32,7 @@ public static MemberRanks from(final List<MissionMember> missionMembers) {
previousVerificationCount = missionMember.getVerificationCount();
}

return new MemberRanks(memberRanks);
return new MemberRanks(Collections.unmodifiableList(memberRanks));
}

private static List<MissionMember> sortedMembersByVerificationCountDesc(final List<MissionMember> missionMembers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> nickname,
@Schema(description = "장기말 타입", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
CharacterType characterType
Optional<CharacterType> 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,
Expand Down
43 changes: 14 additions & 29 deletions src/test/java/com/nexters/goalpanzi/domain/member/MemberTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading