From bac827783276f5e2edfeb0b8c6acd2a6e286e635 Mon Sep 17 00:00:00 2001 From: jimini1026 <128363259+jimini1026@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:18:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=C3=A3=C2=84feat:=20=EB=A7=88=EC=9D=B4?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=9D=B4=EB=A6=84=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #133 --- src/main/java/doore/DooreApplication.java | 1 - .../java/doore/member/api/MemberController.java | 6 ++++++ .../member/application/MemberCommandService.java | 12 ++++++++++++ src/main/resources/application.yml | 2 +- .../application/MemberCommandServiceTest.java | 10 ++++++++++ .../doore/restdocs/docs/MemberApiDocsTest.java | 16 ++++++++++++++++ 6 files changed, 45 insertions(+), 2 deletions(-) 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 162f33e7..1bc76706 100644 --- a/src/main/java/doore/member/api/MemberController.java +++ b/src/main/java/doore/member/api/MemberController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.DeleteMapping; 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 @@ -38,4 +39,9 @@ public ResponseEntity deleteMember(@LoginMember Member member) { return ResponseEntity.noContent().build(); } + @PatchMapping("/profile/name") + public ResponseEntity updateMyPageName(@RequestBody String newName, @LoginMember Member member) { + memberCommandService.updateMyPageName(member.getId(), newName); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/java/doore/member/application/MemberCommandService.java b/src/main/java/doore/member/application/MemberCommandService.java index 1ee2e9bb..0f3dcc81 100644 --- a/src/main/java/doore/member/application/MemberCommandService.java +++ b/src/main/java/doore/member/application/MemberCommandService.java @@ -100,4 +100,16 @@ private Team validateExistTeam(Long teamId) { private Study validateExistStudy(Long studyId) { return studyRepository.findById(studyId).orElseThrow(() -> new StudyException(NOT_FOUND_STUDY)); } + + public void updateMyPageName(Long memberId, String newName) { + Member member = validateExistMember(memberId); + Member updatedMember = Member.builder() + .id(memberId) + .name(newName) + .googleId(member.getGoogleId()) + .email(member.getEmail()) + .imageUrl(member.getImageUrl()) + .build(); + memberRepository.save(updatedMember); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e3e91ec1..9bf95699 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,7 +2,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/doore username: root - password: 1234 + password: dlawlals9! driver-class-name: com.mysql.cj.jdbc.Driver sql: init: diff --git a/src/test/java/doore/member/application/MemberCommandServiceTest.java b/src/test/java/doore/member/application/MemberCommandServiceTest.java index 89431060..d428af64 100644 --- a/src/test/java/doore/member/application/MemberCommandServiceTest.java +++ b/src/test/java/doore/member/application/MemberCommandServiceTest.java @@ -227,4 +227,14 @@ void init() { memberCommandService.transferStudyLeader(study.getId(), member.getId(), notStudyLeaderMember.getId()); }); } + + @Test + @DisplayName("[성공] 프로필 이름 수정에 성공한다.") + void updateMyPageName_프로필_이름_수정에_성공한다_성공() { + String updateName = "요시"; + memberCommandService.updateMyPageName(member.getId(), updateName); + + Member findMember = memberRepository.findById(member.getId()).get(); + assertThat(findMember.getName()).isEqualTo(updateName); + } } diff --git a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java index 2619f388..021d47e1 100644 --- a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java +++ b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java @@ -13,6 +13,7 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; public class MemberApiDocsTest extends RestDocsTest { @@ -61,4 +62,19 @@ void setUp() { .andDo(document("delete-member")); } + //todo: docs code + + @Test + @DisplayName("[성공] 프로필 이름 수정에 성공한다.") + void updateMyPageName_프로필_이름_수정에_성공한다() throws Exception { + String requestJson = "{\"newName\":\"요시\"}"; + doNothing().when(memberCommandService).updateMyPageName(any(), any()); + + mockMvc.perform(RestDocumentationRequestBuilders.patch("/profile/name") + .contentType(MediaType.APPLICATION_JSON) + .content(requestJson) + .header(HttpHeaders.AUTHORIZATION, accessToken)) + .andExpect(status().isNoContent()) + .andDo(document("update-my-page-name")); + } } From 6a4405c4924eb626f4bc42f90bc1c16975923926 Mon Sep 17 00:00:00 2001 From: jimini1026 <128363259+jimini1026@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:32:13 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=EB=B9=84=EB=B0=80=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=EC=9E=AC=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9bf95699..e3e91ec1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,7 +2,7 @@ spring: datasource: url: jdbc:mysql://localhost:3306/doore username: root - password: dlawlals9! + password: 1234 driver-class-name: com.mysql.cj.jdbc.Driver sql: init: From 6aa2662414f00c96eff0e6399f06bdd3f41e27b0 Mon Sep 17 00:00:00 2001 From: jimini1026 <128363259+jimini1026@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:38:17 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20=ED=95=A8=EC=88=98=EB=AA=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doore/member/api/MemberController.java | 9 +++-- .../application/MemberCommandService.java | 13 ++++--- .../dto/request/MemberUpdateRequest.java | 8 +++++ .../application/MemberCommandServiceTest.java | 36 ++++++++++++++++--- .../restdocs/docs/MemberApiDocsTest.java | 12 ++++--- 5 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java diff --git a/src/main/java/doore/member/api/MemberController.java b/src/main/java/doore/member/api/MemberController.java index 1bc76706..e2a26eb4 100644 --- a/src/main/java/doore/member/api/MemberController.java +++ b/src/main/java/doore/member/api/MemberController.java @@ -1,6 +1,7 @@ package doore.member.api; import doore.member.application.MemberCommandService; +import doore.member.application.dto.request.MemberUpdateRequest; import doore.member.domain.Member; import doore.resolver.LoginMember; import lombok.RequiredArgsConstructor; @@ -39,9 +40,11 @@ public ResponseEntity deleteMember(@LoginMember Member member) { return ResponseEntity.noContent().build(); } - @PatchMapping("/profile/name") - public ResponseEntity updateMyPageName(@RequestBody String newName, @LoginMember Member member) { - memberCommandService.updateMyPageName(member.getId(), newName); + @PatchMapping("/profile/members/{memberId}") + public ResponseEntity updateMyPage(@PathVariable Long memberId, + @RequestBody MemberUpdateRequest memberUpdateRequest, + @LoginMember Member member) { + memberCommandService.updateMyPage(member.getId(), memberId, memberUpdateRequest); return ResponseEntity.noContent().build(); } } diff --git a/src/main/java/doore/member/application/MemberCommandService.java b/src/main/java/doore/member/application/MemberCommandService.java index 0f3dcc81..ba8a91e3 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; @@ -101,11 +102,15 @@ private Study validateExistStudy(Long studyId) { return studyRepository.findById(studyId).orElseThrow(() -> new StudyException(NOT_FOUND_STUDY)); } - public void updateMyPageName(Long memberId, String newName) { - Member member = validateExistMember(memberId); + public void updateMyPage(Long tokenMemberId, Long pathMemberId, MemberUpdateRequest memberUpdateRequest) { + if (!tokenMemberId.equals(pathMemberId)) { + throw new MemberException(UNAUTHORIZED); + } + + Member member = validateExistMember(pathMemberId); Member updatedMember = Member.builder() - .id(memberId) - .name(newName) + .id(pathMemberId) + .name(memberUpdateRequest.getNewName()) .googleId(member.getGoogleId()) .email(member.getEmail()) .imageUrl(member.getImageUrl()) 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..641d00f9 --- /dev/null +++ b/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java @@ -0,0 +1,8 @@ +package doore.member.application.dto.request; + +import lombok.Data; + +@Data +public class MemberUpdateRequest { + private String newName; +} diff --git a/src/test/java/doore/member/application/MemberCommandServiceTest.java b/src/test/java/doore/member/application/MemberCommandServiceTest.java index d428af64..4a7e3a76 100644 --- a/src/test/java/doore/member/application/MemberCommandServiceTest.java +++ b/src/test/java/doore/member/application/MemberCommandServiceTest.java @@ -7,6 +7,7 @@ import static doore.member.domain.TeamRoleType.ROLE_팀원; import static doore.member.domain.TeamRoleType.ROLE_팀장; import static doore.member.exception.MemberExceptionType.NOT_FOUND_MEMBER; +import static doore.member.exception.MemberExceptionType.UNAUTHORIZED; import static doore.team.exception.TeamExceptionType.NOT_FOUND_TEAM; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -14,6 +15,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; @@ -231,10 +233,36 @@ void init() { @Test @DisplayName("[성공] 프로필 이름 수정에 성공한다.") void updateMyPageName_프로필_이름_수정에_성공한다_성공() { - String updateName = "요시"; - memberCommandService.updateMyPageName(member.getId(), updateName); + MemberUpdateRequest request = new MemberUpdateRequest(); + request.setNewName("요시"); - Member findMember = memberRepository.findById(member.getId()).get(); - assertThat(findMember.getName()).isEqualTo(updateName); + memberCommandService.updateMyPage(member.getId(), member.getId(), request); + + Member findMember = memberRepository.findById(member.getId()).orElseThrow(); + assertThat(findMember.getName()).isEqualTo("요시"); + } + + @Test + @DisplayName("[실패] 프로필 이름 수정 시 유효하지 않은 회원이면 실패한다.") + void updateMyPageName_유효하지_않은_회원이_프로필_이름_수정을_시도하면_실패한다() { + Long invalidMemberId = 10L; + + MemberUpdateRequest request = new MemberUpdateRequest(); + request.setNewName("요시"); + + assertThatThrownBy(() -> { + memberCommandService.updateMyPage(member.getId(), invalidMemberId, request); + }).isInstanceOf(MemberException.class).hasMessage(NOT_FOUND_MEMBER.errorMessage()); + } + + @Test + @DisplayName("[실패] 프로필 이름 수정 시 권한이 없으면 실패한다.") + void updateMyPageName_권한이_없는_회원이_프로필_이름_수정을_시도하면_실패한다() { + MemberUpdateRequest request = new MemberUpdateRequest(); + request.setNewName("요시"); + + assertThatThrownBy(() -> { + memberCommandService.updateMyPage(2L, member.getId(), request); + }).isInstanceOf(MemberException.class).hasMessage(UNAUTHORIZED.errorMessage()); } } diff --git a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java index 021d47e1..11a8c451 100644 --- a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java +++ b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java @@ -8,6 +8,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.restdocs.RestDocsTest; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -62,19 +63,20 @@ void setUp() { .andDo(document("delete-member")); } - //todo: docs code - @Test @DisplayName("[성공] 프로필 이름 수정에 성공한다.") void updateMyPageName_프로필_이름_수정에_성공한다() throws Exception { String requestJson = "{\"newName\":\"요시\"}"; - doNothing().when(memberCommandService).updateMyPageName(any(), any()); + doNothing().when(memberCommandService) + .updateMyPage(any(Long.class), any(Long.class), any(MemberUpdateRequest.class)); - mockMvc.perform(RestDocumentationRequestBuilders.patch("/profile/name") + mockMvc.perform(RestDocumentationRequestBuilders.patch("/profile/members/{memberId}", 1) .contentType(MediaType.APPLICATION_JSON) .content(requestJson) .header(HttpHeaders.AUTHORIZATION, accessToken)) .andExpect(status().isNoContent()) - .andDo(document("update-my-page-name")); + .andDo(document("update-my-page-name", pathParameters( + parameterWithName("memberId").description("회원 id") + ))); } } From 077c3f3f455614ecd4d3b711d8a3e3a779aece29 Mon Sep 17 00:00:00 2001 From: jimini1026 <128363259+jimini1026@users.noreply.github.com> Date: Sat, 17 Aug 2024 16:03:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=20=ED=94=BC=EB=93=9C=EB=B0=B1?= =?UTF-8?q?=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doore/member/api/MemberController.java | 10 ++-- .../application/MemberCommandService.java | 20 ++----- .../dto/request/MemberUpdateRequest.java | 9 +-- src/main/java/doore/member/domain/Member.java | 4 ++ .../application/MemberCommandServiceTest.java | 46 +++++++-------- .../restdocs/docs/MemberApiDocsTest.java | 58 +++++++++++++++++-- 6 files changed, 92 insertions(+), 55 deletions(-) diff --git a/src/main/java/doore/member/api/MemberController.java b/src/main/java/doore/member/api/MemberController.java index 1720eb6f..46e1d9b9 100644 --- a/src/main/java/doore/member/api/MemberController.java +++ b/src/main/java/doore/member/api/MemberController.java @@ -46,11 +46,11 @@ public ResponseEntity deleteMember(@LoginMember final Member member) { return ResponseEntity.noContent().build(); } - @PatchMapping("/profile/members/{memberId}") - public ResponseEntity updateMyPage(@PathVariable Long memberId, - @RequestBody MemberUpdateRequest memberUpdateRequest, - @LoginMember Member member) { - memberCommandService.updateMyPage(member.getId(), memberId, memberUpdateRequest); + @PatchMapping("/profile/members") + public ResponseEntity updateMyPage( + @RequestBody final MemberUpdateRequest memberUpdateRequest, + @LoginMember final Member member) { + memberCommandService.updateMyPage(member.getId(), memberUpdateRequest); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/doore/member/application/MemberCommandService.java b/src/main/java/doore/member/application/MemberCommandService.java index 8e11c71f..dceda2ff 100644 --- a/src/main/java/doore/member/application/MemberCommandService.java +++ b/src/main/java/doore/member/application/MemberCommandService.java @@ -90,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)); } @@ -102,19 +102,9 @@ private Study validateExistStudy(final Long studyId) { return studyRepository.findById(studyId).orElseThrow(() -> new StudyException(NOT_FOUND_STUDY)); } - public void updateMyPage(Long tokenMemberId, Long pathMemberId, MemberUpdateRequest memberUpdateRequest) { - if (!tokenMemberId.equals(pathMemberId)) { - throw new MemberException(UNAUTHORIZED); - } - - Member member = validateExistMember(pathMemberId); - Member updatedMember = Member.builder() - .id(pathMemberId) - .name(memberUpdateRequest.getNewName()) - .googleId(member.getGoogleId()) - .email(member.getEmail()) - .imageUrl(member.getImageUrl()) - .build(); - memberRepository.save(updatedMember); + 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 index 641d00f9..e9366df2 100644 --- a/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java +++ b/src/main/java/doore/member/application/dto/request/MemberUpdateRequest.java @@ -1,8 +1,9 @@ package doore.member.application.dto.request; -import lombok.Data; +import lombok.Builder; -@Data -public class MemberUpdateRequest { - private String newName; +@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 dd9d7bb6..761d14e8 100644 --- a/src/test/java/doore/member/application/MemberCommandServiceTest.java +++ b/src/test/java/doore/member/application/MemberCommandServiceTest.java @@ -7,7 +7,6 @@ import static doore.member.domain.TeamRoleType.ROLE_팀원; import static doore.member.domain.TeamRoleType.ROLE_팀장; import static doore.member.exception.MemberExceptionType.NOT_FOUND_MEMBER; -import static doore.member.exception.MemberExceptionType.UNAUTHORIZED; import static doore.team.exception.TeamExceptionType.NOT_FOUND_TEAM; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -233,38 +232,33 @@ void init() { } @Test - @DisplayName("[성공] 프로필 이름 수정에 성공한다.") - void updateMyPageName_프로필_이름_수정에_성공한다_성공() { - MemberUpdateRequest request = new MemberUpdateRequest(); - request.setNewName("요시"); - - memberCommandService.updateMyPage(member.getId(), member.getId(), request); + @DisplayName("[성공] 멤버 조회에 성공한다.") + void validateExistMember_멤버_조회에_성공한다() { + Member savedMember = memberCommandService.validateExistMember( + member.getId() + ); - Member findMember = memberRepository.findById(member.getId()).orElseThrow(); - assertThat(findMember.getName()).isEqualTo("요시"); + assertThat(savedMember).isEqualTo(member); } @Test - @DisplayName("[실패] 프로필 이름 수정 시 유효하지 않은 회원이면 실패한다.") - void updateMyPageName_유효하지_않은_회원이_프로필_이름_수정을_시도하면_실패한다() { - Long invalidMemberId = 10L; - - MemberUpdateRequest request = new MemberUpdateRequest(); - request.setNewName("요시"); - - assertThatThrownBy(() -> { - memberCommandService.updateMyPage(member.getId(), invalidMemberId, request); - }).isInstanceOf(MemberException.class).hasMessage(NOT_FOUND_MEMBER.errorMessage()); + @DisplayName("[실패] 멤버 조회에 실패한다.") + void validateExistMember_멤버_조회에_실패한다() { + assertThatThrownBy(() -> memberCommandService.validateExistMember(member.getId() + 1)) + .isInstanceOf(MemberException.class) + .hasMessage(NOT_FOUND_MEMBER.errorMessage()); } @Test - @DisplayName("[실패] 프로필 이름 수정 시 권한이 없으면 실패한다.") - void updateMyPageName_권한이_없는_회원이_프로필_이름_수정을_시도하면_실패한다() { - MemberUpdateRequest request = new MemberUpdateRequest(); - request.setNewName("요시"); + @DisplayName("[성공] 프로필 이름 수정에 성공한다.") + void updateMyPage_프로필_이름_수정에_성공한다() { + MemberUpdateRequest request = MemberUpdateRequest.builder() + .newName("요시") + .build(); - assertThatThrownBy(() -> { - memberCommandService.updateMyPage(2L, member.getId(), request); - }).isInstanceOf(MemberException.class).hasMessage(UNAUTHORIZED.errorMessage()); + 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 ca70726c..56b8d163 100644 --- a/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java +++ b/src/test/java/doore/restdocs/docs/MemberApiDocsTest.java @@ -4,18 +4,26 @@ import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; +import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; 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; +import doore.team.application.dto.response.MyTeamsAndStudiesResponse; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders; +import org.springframework.restdocs.payload.ResponseFieldsSnippet; +import org.springframework.restdocs.request.PathParametersSnippet; public class MemberApiDocsTest extends RestDocsTest { private String accessToken; @@ -63,19 +71,59 @@ void setUp() { .andDo(document("delete-member")); } + @Test + @DisplayName("[성공] 사이드바에 들어가는 정보를 조회한다.") + void getSideBarInfo_사이드바에_들어가는_정보를_조회한다_성공() throws Exception { + //given + final Long memberId = 1L; + final List studyResponses = List.of( + new StudyNameResponse(1L, "알고리즘 스터디"), + new StudyNameResponse(2L, "개발 스터디") + ); + final List response = List.of( + new MyTeamsAndStudiesResponse(1L, "BDD", studyResponses) + ); + final MemberAndMyTeamsAndStudiesResponse memberAndMyTeamsAndStudiesResponse = new MemberAndMyTeamsAndStudiesResponse( + 1L, "이름", "프로필사진", response); + final PathParametersSnippet pathParameters = pathParameters( + parameterWithName("memberId").description("사이드바 정보목록을 조회하는 회원 ID") + ); + final ResponseFieldsSnippet responseFieldsSnippet = responseFields( + numberFieldWithPath("id", "멤버 ID"), + stringFieldWithPath("name", "멤버 이름"), + stringFieldWithPath("imageUrl", "멤버 프로필 경로"), + numberFieldWithPath("myTeamsAndStudies[].teamId", "팀 ID"), + stringFieldWithPath("myTeamsAndStudies[].teamName", "팀 이름"), + numberFieldWithPath("myTeamsAndStudies[].teamStudies[].id", "팀에 포함되는 스터디 id"), + stringFieldWithPath("myTeamsAndStudies.[].teamStudies[].name", "팀에 포함되는 스터디 이름") + ); + + //when + when(memberQueryService.getSideBarInfo(any(), any())).thenReturn(memberAndMyTeamsAndStudiesResponse); + + //then + mockMvc.perform(get("/members/{memberId}", memberId) + .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(document("get-sidebar-info", pathParameters, responseFieldsSnippet)); + } + @Test @DisplayName("[성공] 프로필 이름 수정에 성공한다.") void updateMyPageName_프로필_이름_수정에_성공한다() throws Exception { - String requestJson = "{\"newName\":\"요시\"}"; + + MemberUpdateRequest request = new MemberUpdateRequest("요시"); + String requestJson = objectMapper.writeValueAsString(request); + doNothing().when(memberCommandService) - .updateMyPage(any(Long.class), any(Long.class), any(MemberUpdateRequest.class)); + .updateMyPage(any(Long.class), any(MemberUpdateRequest.class)); - mockMvc.perform(RestDocumentationRequestBuilders.patch("/profile/members/{memberId}", 1) + 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", pathParameters( - parameterWithName("memberId").description("회원 id")))); + .andDo(document("update-my-page-name")); } }