diff --git a/backend/src/main/java/com/funeat/member/application/MemberService.java b/backend/src/main/java/com/funeat/member/application/MemberService.java index b1d55931a..6ac06698b 100644 --- a/backend/src/main/java/com/funeat/member/application/MemberService.java +++ b/backend/src/main/java/com/funeat/member/application/MemberService.java @@ -3,6 +3,7 @@ import com.funeat.auth.dto.SignUserDto; import com.funeat.auth.dto.UserInfoDto; import com.funeat.member.domain.Member; +import com.funeat.member.dto.MemberRequest; import com.funeat.member.persistence.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,4 +33,13 @@ public SignUserDto save(final UserInfoDto userInfoDto) { return SignUserDto.of(true, member); } + + @Transactional + public void modify(final Long memberId, final MemberRequest request) { + final Member findMember = memberRepository.findById(memberId) + .orElseThrow(IllegalArgumentException::new); + + findMember.modifyNickname(request.getNickname()); + findMember.modifyProfileImage(request.getProfileImage()); + } } diff --git a/backend/src/main/java/com/funeat/member/dto/MemberRequest.java b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java new file mode 100644 index 000000000..a4800c6ed --- /dev/null +++ b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java @@ -0,0 +1,20 @@ +package com.funeat.member.dto; + +public class MemberRequest { + + private final String nickname; + private final String profileImage; + + public MemberRequest(final String nickname, final String profileImage) { + this.nickname = nickname; + this.profileImage = profileImage; + } + + public String getNickname() { + return nickname; + } + + public String getProfileImage() { + return profileImage; + } +} diff --git a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java index 65967f853..ddb281c7f 100644 --- a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java +++ b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java @@ -5,6 +5,7 @@ import com.funeat.auth.dto.UserInfoDto; import com.funeat.common.DataClearExtension; import com.funeat.member.domain.Member; +import com.funeat.member.dto.MemberRequest; import com.funeat.member.persistence.MemberRepository; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Assertions; @@ -71,4 +72,122 @@ class findOrCreateMember_테스트 { }); } } + + @Nested + class modify_테스트 { + + @Test + void 닉네임과_프로필_사진이_그대로면_사용자_정보는_바뀌지_않는다() { + // given + final var nickname = "test"; + final var profileImage = "http://www.test.com"; + final MemberRequest request = new MemberRequest(nickname, profileImage); + + final var member = new Member(nickname, profileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임만_바뀌고_프로필_사진은_그대로면_닉네임만_바뀐다() { + // given + final var beforeNickname = "before"; + final var profileImage = "http://www.test.com"; + final var afterNickname = "after"; + final MemberRequest request = new MemberRequest(afterNickname, profileImage); + + final var member = new Member(beforeNickname, profileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isNotEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임은_그대로이고_프로필_사진이_바뀌면_프로필_사진만_바뀐다() { + // given + final var nickname = "test"; + final var beforeProfileImage = "http://www.before.com"; + final var afterProfileImage = "http://www.after.com"; + + final MemberRequest request = new MemberRequest(nickname, afterProfileImage); + + final var member = new Member(nickname, beforeProfileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isNotEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임과_프로필_사진_모두_바뀌면_모두_바뀐다() { + // given + final var beforeNickname = "before"; + final var afterNickname = "after"; + final var beforeProfileImage = "http://www.before.com"; + final var afterProfileImage = "http://www.after.com"; + + final MemberRequest request = new MemberRequest(afterNickname, afterProfileImage); + + final var member = new Member(beforeNickname, beforeProfileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isNotEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isNotEqualTo(expectedProfileImage); + }); + } + } }