-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: 비밀번호 변경 api의 위치를 command service 레이어로 이동 #238 * feat: 회원의 기본정보(이름, 전화번호)수정 API 구현 및 테스트 코드 구현 #238 * refactor: 변경 도메인이 상단에 존재하도록 request 파일 명 변경 #238
- Loading branch information
Showing
11 changed files
with
127 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
backend/src/main/java/sw_css/member/application/MemberCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package sw_css.member.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import sw_css.member.domain.Member; | ||
import sw_css.member.domain.embedded.Password; | ||
import sw_css.member.domain.repository.MemberRepository; | ||
import sw_css.member.exception.MemberException; | ||
import sw_css.member.exception.MemberExceptionType; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class MemberCommandService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public void changePassword(Member me, String oldPassword, String newPassword) { | ||
if (me.isWrongPassword(oldPassword)) { | ||
throw new MemberException(MemberExceptionType.MEMBER_WRONG_PASSWORD); | ||
} | ||
|
||
String encodedPassword = Password.encode(newPassword); | ||
me.setPassword(encodedPassword); | ||
|
||
memberRepository.save(me); | ||
} | ||
|
||
public void changeDefaultInfo(final Member me, final String name, final String phoneNumber) { | ||
me.setName(name); | ||
me.setPhoneNumber(phoneNumber); | ||
|
||
memberRepository.save(me); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
backend/src/main/java/sw_css/member/application/dto/request/ChangePasswordRequest.java
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/sw_css/member/application/dto/request/MemberChangeInfoRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package sw_css.member.application.dto.request; | ||
|
||
import jakarta.validation.constraints.Pattern; | ||
import sw_css.member.domain.embedded.PhoneNumber; | ||
import sw_css.member.domain.embedded.RealName; | ||
|
||
public record MemberChangeInfoRequest( | ||
@Pattern(regexp = RealName.NAME_REGEX, message = RealName.NAME_INVALID) | ||
String name, | ||
@Pattern(regexp = PhoneNumber.PHONE_NUMBER_REGEX, message = PhoneNumber.PHONE_NUMBER_INVALID) | ||
String phoneNumber) { | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/sw_css/member/application/dto/request/MemberChangePasswordRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sw_css.member.application.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import sw_css.member.domain.embedded.Password; | ||
|
||
public record MemberChangePasswordRequest( | ||
@NotBlank(message = "이전 비밀번호 값을 입력해주세요.") | ||
String oldPassword, | ||
@Pattern(regexp = Password.PASSWORD_REGEX, message = Password.PASSWORD_INVALID) | ||
String newPassword) { | ||
|
||
public static MemberChangePasswordRequest from(String oldPassword, String newPassword) { | ||
return new MemberChangePasswordRequest(oldPassword, newPassword); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,8 @@ | |
import org.springframework.restdocs.payload.ResponseFieldsSnippet; | ||
import org.springframework.restdocs.request.PathParametersSnippet; | ||
import sw_css.member.api.MemberController; | ||
import sw_css.member.application.dto.request.ChangePasswordRequest; | ||
import sw_css.member.application.dto.request.MemberChangePasswordRequest; | ||
import sw_css.member.application.dto.request.MemberChangeInfoRequest; | ||
import sw_css.member.application.dto.response.StudentMemberResponse; | ||
import sw_css.member.domain.Member; | ||
import sw_css.restdocs.RestDocsTest; | ||
|
@@ -77,10 +78,10 @@ public void changePassword() throws Exception { | |
final String newPassword = "asdf1234!"; | ||
final String token = "Bearer AccessToken"; | ||
|
||
final ChangePasswordRequest request = new ChangePasswordRequest(oldPassword, newPassword); | ||
final MemberChangePasswordRequest request = new MemberChangePasswordRequest(oldPassword, newPassword); | ||
|
||
// when | ||
doNothing().when(memberQueryService).changePassword(me, oldPassword, newPassword); | ||
doNothing().when(memberCommandService).changePassword(me, oldPassword, newPassword); | ||
|
||
// then | ||
mockMvc.perform(RestDocumentationRequestBuilders.patch("/members/change-password") | ||
|
@@ -90,4 +91,30 @@ public void changePassword() throws Exception { | |
.andExpect(status().isNoContent()) | ||
.andDo(document("member-change-password", requestFields)); | ||
} | ||
|
||
@Test | ||
@DisplayName("[성공] 회원은 이름과 전화번호를 변경할 수 있다.") | ||
public void changeDefaultInfo() throws Exception { | ||
// given | ||
final RequestFieldsSnippet requestFields = requestFields( | ||
fieldWithPath("name").type(JsonFieldType.STRING).description("회원의 이름"), | ||
fieldWithPath("phoneNumber").type(JsonFieldType.STRING).description("회원의 전화번호") | ||
); | ||
|
||
final Member me = new Member(1L, "[email protected]", "ddang", "qwer1234!", "01012341234"); | ||
final String token = "Bearer AccessToken"; | ||
|
||
final MemberChangeInfoRequest request = new MemberChangeInfoRequest("이다은", "01031315656"); | ||
|
||
// when | ||
doNothing().when(memberCommandService).changePassword(me, request.name(), request.phoneNumber()); | ||
|
||
// then | ||
mockMvc.perform(RestDocumentationRequestBuilders.patch("/members/change-info") | ||
.contentType(APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(request)) | ||
.header(HttpHeaders.AUTHORIZATION, token)) | ||
.andExpect(status().isNoContent()) | ||
.andDo(document("member-change-info", requestFields)); | ||
} | ||
} |