From 55d191ba001d51a714918980c713b3383c509f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A7=84?= Date: Mon, 16 Oct 2023 11:12:16 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8F=99=ED=99=94=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8CAPI,=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=20=EA=B8=B0=EC=A1=B4=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EC=99=80=20=EB=B9=84=EA=B5=90=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../englishfairytale/exception/code/ErrorCode.java | 1 + .../englishfairytale/exception/code/MemberCode.java | 1 + .../member/application/MemberCommandService.java | 5 +++-- .../application/dto/MemberUpdatePasswordCommand.java | 3 ++- .../hanium/englishfairytale/member/domain/Member.java | 11 +++++++++-- .../member/infra/http/MemberController.java | 10 +++++----- .../member/infra/http/MemberDtoConverter.java | 7 ++++--- .../infra/http/dto/MemberUpdatePasswordDto.java | 5 +++-- .../tale/application/dto/TalesInfo.java | 5 +++++ 9 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/main/java/hanium/englishfairytale/exception/code/ErrorCode.java b/src/main/java/hanium/englishfairytale/exception/code/ErrorCode.java index c4b5e1a..6f2120d 100644 --- a/src/main/java/hanium/englishfairytale/exception/code/ErrorCode.java +++ b/src/main/java/hanium/englishfairytale/exception/code/ErrorCode.java @@ -37,6 +37,7 @@ public enum ErrorCode { DUPLICATED_NICKNAME(MemberCode.NICKNAME_DUPLICATED.getCode(), CONFLICT, "동일한 닉네임이 존재하는 경우"), MEMBER_IMAGE_NON_EXISTED(MemberCode.NON_EXISTED_IMAGE.getCode(), CONFLICT, "삭제할 이미지가 존재하지 않는 경우"), LOGIN_FAILED(MemberCode.FAILED_LOGIN.getCode(), NOT_FOUND, "아이디 또는 비밀번호가 일치하지 않는 경우"), + INVALID_PASSWORD(MemberCode.INVALID_PASSWORD.getCode(), BAD_REQUEST, "기존의 비밀번호와 일치하지 않는 경우"), // NOTICE ANNOUNCE_NOT_FOUND(AnnouncementCode.ANNOUNCEMENT_NOT_FOUND.getCode(), NOT_FOUND, "DB에 해당 Announcement의 데이터가 존재하지 않는 경우"), diff --git a/src/main/java/hanium/englishfairytale/exception/code/MemberCode.java b/src/main/java/hanium/englishfairytale/exception/code/MemberCode.java index c2ab4bf..2485ef7 100644 --- a/src/main/java/hanium/englishfairytale/exception/code/MemberCode.java +++ b/src/main/java/hanium/englishfairytale/exception/code/MemberCode.java @@ -11,6 +11,7 @@ public enum MemberCode { NICKNAME_DUPLICATED("M-003"), NON_EXISTED_IMAGE("M-004"), FAILED_LOGIN("M-005"), + INVALID_PASSWORD("M-006"), ; private final String code; diff --git a/src/main/java/hanium/englishfairytale/member/application/MemberCommandService.java b/src/main/java/hanium/englishfairytale/member/application/MemberCommandService.java index 6d4816d..f104741 100644 --- a/src/main/java/hanium/englishfairytale/member/application/MemberCommandService.java +++ b/src/main/java/hanium/englishfairytale/member/application/MemberCommandService.java @@ -34,7 +34,7 @@ public Long register(MemberRegisterCommand memberRegisterCommand) { @Transactional public Long login(MemberLoginCommand memberLoginCommand) { Member member = findMemberForLogin(memberLoginCommand); - member.verifyCorrectPassword(memberLoginCommand); + member.verifyMemberEmailAndPassword(memberLoginCommand); return member.getId(); } @@ -47,7 +47,8 @@ public void updateNickname(Long memberId, String nickname) { @Transactional public void updatePassword(MemberUpdatePasswordCommand updatePasswordCommand) { Member member = findMember(updatePasswordCommand.getMemberId()); - member.updatePassword(updatePasswordCommand.getPassword()); + member.verifyMemberPassword(updatePasswordCommand.getOriginalPassword()); + member.updatePassword(updatePasswordCommand.getNewPassword()); } @Transactional diff --git a/src/main/java/hanium/englishfairytale/member/application/dto/MemberUpdatePasswordCommand.java b/src/main/java/hanium/englishfairytale/member/application/dto/MemberUpdatePasswordCommand.java index e069eb2..17fdd49 100644 --- a/src/main/java/hanium/englishfairytale/member/application/dto/MemberUpdatePasswordCommand.java +++ b/src/main/java/hanium/englishfairytale/member/application/dto/MemberUpdatePasswordCommand.java @@ -11,5 +11,6 @@ @Builder public class MemberUpdatePasswordCommand { Long memberId; - String password; + String originalPassword; + String newPassword; } diff --git a/src/main/java/hanium/englishfairytale/member/domain/Member.java b/src/main/java/hanium/englishfairytale/member/domain/Member.java index db366a5..9d1ee99 100644 --- a/src/main/java/hanium/englishfairytale/member/domain/Member.java +++ b/src/main/java/hanium/englishfairytale/member/domain/Member.java @@ -3,6 +3,7 @@ import hanium.englishfairytale.exception.BusinessException; import hanium.englishfairytale.exception.code.ErrorCode; import hanium.englishfairytale.member.application.dto.MemberLoginCommand; +import hanium.englishfairytale.member.application.dto.MemberUpdatePasswordCommand; import hanium.englishfairytale.tale.domain.Tale; import lombok.AccessLevel; import lombok.Builder; @@ -90,9 +91,15 @@ public void makeImageNull() { this.image = null; } - public void verifyCorrectPassword(MemberLoginCommand memberLoginCommand) { - if (!Objects.equals(password, memberLoginCommand.getPassword())) { + public void verifyMemberEmailAndPassword(MemberLoginCommand memberLoginCommand) { + if (!Objects.equals(password, memberLoginCommand.getPassword()) || !Objects.equals(email, memberLoginCommand.getEmail())) { throw new BusinessException(ErrorCode.LOGIN_FAILED); } } + + public void verifyMemberPassword(String originalPassword) { + if (!Objects.equals(password, originalPassword)) { + throw new BusinessException(ErrorCode.INVALID_PASSWORD); + } + } } diff --git a/src/main/java/hanium/englishfairytale/member/infra/http/MemberController.java b/src/main/java/hanium/englishfairytale/member/infra/http/MemberController.java index a3ddf16..da2d9fe 100644 --- a/src/main/java/hanium/englishfairytale/member/infra/http/MemberController.java +++ b/src/main/java/hanium/englishfairytale/member/infra/http/MemberController.java @@ -53,9 +53,9 @@ public void updateNickname(@RequestParam Long memberId, @RequestParam String nic memberCommandService.updateNickname(memberId, nickname); } - @PatchMapping("/password") - public void updatePassword(@Validated @RequestBody MemberUpdatePasswordDto updatePasswordDto) { - memberCommandService.updatePassword(toPasswordUpdateCommand(updatePasswordDto)); + @PatchMapping("/password/{memberId}") + public void updatePassword(@PathVariable Long memberId ,@Validated @RequestBody MemberUpdatePasswordDto updatePasswordDto) { + memberCommandService.updatePassword(toPasswordUpdateCommand(memberId, updatePasswordDto)); } @PatchMapping("/{memberId}/image") @@ -72,8 +72,8 @@ private MemberRegisterCommand toCreateCommand(MemberRegisterDto memberRegisterDt return converter.toCommand(memberRegisterDto, image); } - private MemberUpdatePasswordCommand toPasswordUpdateCommand(MemberUpdatePasswordDto updatePasswordDto) { - return converter.toCommand(updatePasswordDto); + private MemberUpdatePasswordCommand toPasswordUpdateCommand(Long memberId, MemberUpdatePasswordDto updatePasswordDto) { + return converter.toCommand(memberId, updatePasswordDto); } private MemberImageUpdateCommand toImageUpdateCommand(Long memberId, MultipartFile image) { diff --git a/src/main/java/hanium/englishfairytale/member/infra/http/MemberDtoConverter.java b/src/main/java/hanium/englishfairytale/member/infra/http/MemberDtoConverter.java index 59779ea..5229052 100644 --- a/src/main/java/hanium/englishfairytale/member/infra/http/MemberDtoConverter.java +++ b/src/main/java/hanium/englishfairytale/member/infra/http/MemberDtoConverter.java @@ -23,10 +23,11 @@ public MemberRegisterCommand toCommand(MemberRegisterDto dto, MultipartFile imag .build(); } - public MemberUpdatePasswordCommand toCommand(MemberUpdatePasswordDto dto) { + public MemberUpdatePasswordCommand toCommand(Long memberId, MemberUpdatePasswordDto dto) { return MemberUpdatePasswordCommand.builder() - .memberId(dto.getMemberId()) - .password(dto.getPassword()) + .memberId(memberId) + .originalPassword(dto.getOriginalPassword()) + .newPassword(dto.getNewPassword()) .build(); } diff --git a/src/main/java/hanium/englishfairytale/member/infra/http/dto/MemberUpdatePasswordDto.java b/src/main/java/hanium/englishfairytale/member/infra/http/dto/MemberUpdatePasswordDto.java index e8d49f0..633536a 100644 --- a/src/main/java/hanium/englishfairytale/member/infra/http/dto/MemberUpdatePasswordDto.java +++ b/src/main/java/hanium/englishfairytale/member/infra/http/dto/MemberUpdatePasswordDto.java @@ -12,8 +12,9 @@ @AllArgsConstructor public class MemberUpdatePasswordDto { @NotNull - private Long memberId; + @Pattern(regexp = "^(?i)(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{2,10}$") + private String originalPassword; @NotNull @Pattern(regexp = "^(?i)(?=.*[a-zA-Z])(?=.*[0-9])[a-zA-Z0-9]{2,10}$") - private String password; + private String newPassword; } diff --git a/src/main/java/hanium/englishfairytale/tale/application/dto/TalesInfo.java b/src/main/java/hanium/englishfairytale/tale/application/dto/TalesInfo.java index f7e8dae..1393d16 100644 --- a/src/main/java/hanium/englishfairytale/tale/application/dto/TalesInfo.java +++ b/src/main/java/hanium/englishfairytale/tale/application/dto/TalesInfo.java @@ -14,11 +14,16 @@ public class TalesInfo { private Long taleId; private String title; + private String imgUrl; + private String imgStatus; private List keywords; public TalesInfo(Tale tale, List keywordList) { this.taleId = tale.getId(); this.title = tale.getTitle(); + this.imgUrl = tale.getImage().getTaleImage() == null ? null : tale.getImage().getUrl(); + this.imgStatus = tale.getImageStatus(); + keywords = new ArrayList<>(); for (Keyword keyword : keywordList) { keywords.add(keyword.getWord());