-
Notifications
You must be signed in to change notification settings - Fork 4
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
Feature/#133-마이페이지_회원_정보_수정_기능을_제작한다 #159
The head ref may contain hidden characters: "Feature/#133-\uB9C8\uC774\uD398\uC774\uC9C0_\uD68C\uC6D0_\uC815\uBCF4_\uC218\uC815_\uAE30\uB2A5\uC744_\uC81C\uC791\uD55C\uB2E4"
Changes from 5 commits
bac8277
6a4405c
0e29cc5
6aa2662
d1c1c58
077c3f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -100,4 +101,20 @@ 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(Long tokenMemberId, Long pathMemberId, MemberUpdateRequest memberUpdateRequest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 final 붙여주세요! 다른 코드에도 동일하게 파라미터와 객체에 붙여주시면 좋을 것 같아요~ |
||
if (!tokenMemberId.equals(pathMemberId)) { | ||
throw new MemberException(UNAUTHORIZED); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public void updateName(String name) {
this.name = name;
} member entity에 해당 코드를 작성하시면 builder를 이용해서 객체를 생성하지 않아도 데이터베이스에 값이 변경될 것 같아요~ 저희가 수정할 데이터는 이름 하나니까용 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package doore.member.application.dto.request; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class MemberUpdateRequest { | ||
private String newName; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희는 request를 record로 생성하고 있습니다! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,15 @@ | |
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; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
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 +231,40 @@ void init() { | |
memberCommandService.transferStudyLeader(study.getId(), member.getId(), notStudyLeaderMember.getId()); | ||
}); | ||
} | ||
|
||
@Test | ||
@DisplayName("[성공] 프로필 이름 수정에 성공한다.") | ||
void updateMyPageName_프로필_이름_수정에_성공한다_성공() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍👍 저희 테스트 이름 작성하는 방식이 조금 복잡한데, 잘하신 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 메서드 이름이 안바뀐 것 같아요! |
||
MemberUpdateRequest request = new MemberUpdateRequest(); | ||
request.setNewName("요시"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
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("요시"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위의 코멘트와 동일합니다! |
||
|
||
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("요시"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 동일합니다! |
||
|
||
assertThatThrownBy(() -> { | ||
memberCommandService.updateMyPage(2L, member.getId(), request); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희가 그리고 |
||
}).isInstanceOf(MemberException.class).hasMessage(UNAUTHORIZED.errorMessage()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,25 +4,18 @@ | |
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.response.MemberAndMyTeamsAndStudiesResponse; | ||
import doore.member.application.dto.request.MemberUpdateRequest; | ||
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; | ||
|
@@ -71,40 +64,18 @@ void setUp() { | |
} | ||
|
||
@Test | ||
@DisplayName("[성공] 사이드바에 들어가는 정보를 조회한다.") | ||
void getSideBarInfo_사이드바에_들어가는_정보를_조회한다_성공() throws Exception { | ||
//given | ||
final Long memberId = 1L; | ||
final List<StudyNameResponse> studyResponses = List.of( | ||
new StudyNameResponse(1L, "알고리즘 스터디"), | ||
new StudyNameResponse(2L, "개발 스터디") | ||
); | ||
final List<MyTeamsAndStudiesResponse> 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", "팀에 포함되는 스터디 이름") | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다른 api 테스트 코드가 삭제된 것 같아요ㅠㅠ 복구해주시면 좋을 것 같습니다ㅠㅠ |
||
@DisplayName("[성공] 프로필 이름 수정에 성공한다.") | ||
void updateMyPageName_프로필_이름_수정에_성공한다() throws Exception { | ||
String requestJson = "{\"newName\":\"요시\"}"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
doNothing().when(memberCommandService) | ||
.updateMyPage(any(Long.class), any(Long.class), any(MemberUpdateRequest.class)); | ||
|
||
//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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이것도용ㅠㅠ |
||
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", pathParameters( | ||
parameterWithName("memberId").description("회원 id")))); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
파라미터에 final 붙여주시면 좋을 것 같아요!