diff --git a/src/main/java/doore/DooreApplication.java b/src/main/java/doore/DooreApplication.java index 7fc123be..e3f50799 100644 --- a/src/main/java/doore/DooreApplication.java +++ b/src/main/java/doore/DooreApplication.java @@ -10,5 +10,4 @@ public class DooreApplication { public static void main(String[] args) { SpringApplication.run(DooreApplication.class, args); } - } diff --git a/src/main/java/doore/member/api/MemberController.java b/src/main/java/doore/member/api/MemberController.java index 1611084f..46e1d9b9 100644 --- a/src/main/java/doore/member/api/MemberController.java +++ b/src/main/java/doore/member/api/MemberController.java @@ -2,6 +2,7 @@ import doore.member.application.MemberCommandService; import doore.member.application.MemberQueryService; +import doore.member.application.dto.request.MemberUpdateRequest; import doore.member.application.dto.response.MemberAndMyTeamsAndStudiesResponse; import doore.member.domain.Member; import doore.resolver.LoginMember; @@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; @Validated @@ -44,9 +46,17 @@ public ResponseEntity deleteMember(@LoginMember final Member member) { return ResponseEntity.noContent().build(); } + @PatchMapping("/profile/members") + public ResponseEntity updateMyPage( + @RequestBody final MemberUpdateRequest memberUpdateRequest, + @LoginMember final Member member) { + memberCommandService.updateMyPage(member.getId(), memberUpdateRequest); + return ResponseEntity.noContent().build(); + } + @GetMapping("/members/{memberId}") public ResponseEntity getSideBarInfo(@PathVariable final Long memberId, - @LoginMember final Member member) { + @LoginMember final Member member) { return ResponseEntity.ok(memberQueryService.getSideBarInfo(memberId, member.getId())); } } diff --git a/src/main/java/doore/member/application/MemberCommandService.java b/src/main/java/doore/member/application/MemberCommandService.java index 58921bc9..dceda2ff 100644 --- a/src/main/java/doore/member/application/MemberCommandService.java +++ b/src/main/java/doore/member/application/MemberCommandService.java @@ -11,6 +11,7 @@ import static doore.team.exception.TeamExceptionType.NOT_FOUND_TEAM; import doore.login.application.dto.response.GoogleAccountProfileResponse; +import doore.member.application.dto.request.MemberUpdateRequest; import doore.member.domain.Member; import doore.member.domain.StudyRole; import doore.member.domain.TeamRole; @@ -89,7 +90,7 @@ public void deleteMember(final Long memberId) { memberRepository.delete(member); } - private Member validateExistMember(final Long memberId) { + public Member validateExistMember(final Long memberId) { return memberRepository.findById(memberId).orElseThrow(() -> new MemberException(NOT_FOUND_MEMBER)); } @@ -100,4 +101,10 @@ private Team validateExistTeam(final Long teamId) { private Study validateExistStudy(final Long studyId) { return studyRepository.findById(studyId).orElseThrow(() -> new StudyException(NOT_FOUND_STUDY)); } + + public void updateMyPage(final Long memberId, final MemberUpdateRequest memberUpdateRequest) { + Member member = validateExistMember(memberId); + member.updateName(memberUpdateRequest.newName()); + memberRepository.save(member); + } } diff --git a/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java b/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java new file mode 100644 index 00000000..e9366df2 --- /dev/null +++ b/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java @@ -0,0 +1,9 @@ +package doore.member.application.dto.request; + +import lombok.Builder; + +@Builder +public record MemberUpdateRequest( + String newName +) { +} diff --git a/src/main/java/doore/member/domain/Member.java b/src/main/java/doore/member/domain/Member.java index 8ebab57a..2c5ebe74 100644 --- a/src/main/java/doore/member/domain/Member.java +++ b/src/main/java/doore/member/domain/Member.java @@ -47,4 +47,8 @@ private Member(final Long id, final String name, final String googleId, final St this.imageUrl = imageUrl; this.isDeleted = false; } + + public void updateName(String name) { + this.name = name; + } } diff --git a/src/test/java/doore/member/application/MemberCommandServiceTest.java b/src/test/java/doore/member/application/MemberCommandServiceTest.java index 9dcb5371..761d14e8 100644 --- a/src/test/java/doore/member/application/MemberCommandServiceTest.java +++ b/src/test/java/doore/member/application/MemberCommandServiceTest.java @@ -14,6 +14,7 @@ import doore.helper.IntegrationTest; import doore.login.application.dto.response.GoogleAccountProfileResponse; +import doore.member.application.dto.request.MemberUpdateRequest; import doore.member.domain.Member; import doore.member.domain.StudyRole; import doore.member.domain.TeamRole; @@ -229,4 +230,35 @@ void init() { memberCommandService.transferStudyLeader(study.getId(), member.getId(), notStudyLeaderMember.getId()); }); } + + @Test + @DisplayName("[성공] 멤버 조회에 성공한다.") + void validateExistMember_멤버_조회에_성공한다() { + Member savedMember = memberCommandService.validateExistMember( + member.getId() + ); + + assertThat(savedMember).isEqualTo(member); + } + + @Test + @DisplayName("[실패] 멤버 조회에 실패한다.") + void validateExistMember_멤버_조회에_실패한다() { + assertThatThrownBy(() -> memberCommandService.validateExistMember(member.getId() + 1)) + .isInstanceOf(MemberException.class) + .hasMessage(NOT_FOUND_MEMBER.errorMessage()); + } + + @Test + @DisplayName("[성공] 프로필 이름 수정에 성공한다.") + void updateMyPage_프로필_이름_수정에_성공한다() { + MemberUpdateRequest request = MemberUpdateRequest.builder() + .newName("요시") + .build(); + + memberCommandService.updateMyPage(member.getId(), request); + + Member findMember = memberRepository.findById(member.getId()).orElseThrow(); + assertThat(findMember.getName()).isEqualTo(request.newName()); + } } diff --git a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java index fb472005..56b8d163 100644 --- a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java +++ b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java @@ -10,6 +10,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.pathParameters; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import doore.member.application.dto.request.MemberUpdateRequest; import doore.member.application.dto.response.MemberAndMyTeamsAndStudiesResponse; import doore.restdocs.RestDocsTest; import doore.study.application.dto.response.StudyNameResponse; @@ -107,4 +108,22 @@ void setUp() { .andExpect(status().isOk()) .andDo(document("get-sidebar-info", pathParameters, responseFieldsSnippet)); } + + @Test + @DisplayName("[성공] 프로필 이름 수정에 성공한다.") + void updateMyPageName_프로필_이름_수정에_성공한다() throws Exception { + + MemberUpdateRequest request = new MemberUpdateRequest("요시"); + String requestJson = objectMapper.writeValueAsString(request); + + doNothing().when(memberCommandService) + .updateMyPage(any(Long.class), any(MemberUpdateRequest.class)); + + mockMvc.perform(RestDocumentationRequestBuilders.patch("/profile/members", 1) + .contentType(MediaType.APPLICATION_JSON) + .content(requestJson) + .header(HttpHeaders.AUTHORIZATION, accessToken)) + .andExpect(status().isNoContent()) + .andDo(document("update-my-page-name")); + } }