From deb028f10d62ab44ae14db24d801a0c9b8218c77 Mon Sep 17 00:00:00 2001 From: Hyunmin Choi Date: Tue, 12 Nov 2024 21:18:58 +0900 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=EB=B9=84=EB=B0=80=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=AC=EC=84=A4=EC=A0=95=20API=20(#101)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 필드명 변경 (#99) * feat: 비밀번호 재설정 API (#99) --- .../domain/account/controller/AccountController.java | 4 ++-- .../server/domain/account/service/AccountService.java | 8 ++++---- .../server/domain/member/controller/MemberController.java | 7 +++++++ .../domain/member/service/MemberCommandService.java | 5 +++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/smunity/server/domain/account/controller/AccountController.java b/src/main/java/com/smunity/server/domain/account/controller/AccountController.java index 183d0ce..2c6bd64 100644 --- a/src/main/java/com/smunity/server/domain/account/controller/AccountController.java +++ b/src/main/java/com/smunity/server/domain/account/controller/AccountController.java @@ -20,8 +20,8 @@ public class AccountController { private final AccountService accountService; @PostMapping("/register") - public ResponseEntity register(@AuthVerified String verifiedUser, @RequestBody @Valid RegisterRequestDto requestDto) { - RegisterResponseDto responseDto = accountService.register(verifiedUser, requestDto); + public ResponseEntity register(@AuthVerified String memberName, @RequestBody @Valid RegisterRequestDto requestDto) { + RegisterResponseDto responseDto = accountService.register(memberName, requestDto); return ResponseEntity.status(HttpStatus.CREATED).body(responseDto); } diff --git a/src/main/java/com/smunity/server/domain/account/service/AccountService.java b/src/main/java/com/smunity/server/domain/account/service/AccountService.java index 6b2032a..d44aea6 100644 --- a/src/main/java/com/smunity/server/domain/account/service/AccountService.java +++ b/src/main/java/com/smunity/server/domain/account/service/AccountService.java @@ -29,8 +29,8 @@ public class AccountService { private final PasswordEncoder passwordEncoder; private final JwtTokenProvider jwtTokenProvider; - public RegisterResponseDto register(String verifiedUser, RegisterRequestDto requestDto) { - validateUser(verifiedUser, requestDto.username()); + public RegisterResponseDto register(String memberName, RegisterRequestDto requestDto) { + validateUser(memberName, requestDto.username()); Member member = requestDto.toEntity(); Year year = yearRepository.findByName(requestDto.username().substring(0, 4)) .orElseThrow(() -> new GeneralException(ErrorCode.YEAR_NOT_FOUND)); @@ -64,8 +64,8 @@ private LoginResponseDto generateToken(Long memberId, MemberRole memberRole) { return LoginResponseDto.of(memberId, memberRole, accessToken, refreshToken); } - private void validateUser(String verifiedUser, String username) { - validateVerified(verifiedUser, username); + private void validateUser(String memberName, String username) { + validateVerified(memberName, username); validateUsername(username); } diff --git a/src/main/java/com/smunity/server/domain/member/controller/MemberController.java b/src/main/java/com/smunity/server/domain/member/controller/MemberController.java index 4a1b5cb..b7987fe 100644 --- a/src/main/java/com/smunity/server/domain/member/controller/MemberController.java +++ b/src/main/java/com/smunity/server/domain/member/controller/MemberController.java @@ -8,6 +8,7 @@ import com.smunity.server.domain.member.service.MemberCommandService; import com.smunity.server.domain.member.service.MemberQueryService; import com.smunity.server.global.security.annotation.AuthMember; +import com.smunity.server.global.security.annotation.AuthVerified; import com.smunity.server.global.validation.annotation.PermissionCheck; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -66,4 +67,10 @@ public ResponseEntity changeDepartment(@AuthMember Long m MemberInfoResponseDto responseDto = memberCommandService.changeDepartment(memberId, requestDto); return ResponseEntity.ok(responseDto); } + + @PatchMapping("/password/reset") + public ResponseEntity changePasswordByAuth(@AuthVerified String memberName, @RequestBody @Valid ChangePasswordRequestDto requestDto) { + MemberInfoResponseDto responseDto = memberCommandService.changePasswordByAuth(memberName, requestDto); + return ResponseEntity.ok(responseDto); + } } diff --git a/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java b/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java index d3ded96..cb4aa09 100644 --- a/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java +++ b/src/main/java/com/smunity/server/domain/member/service/MemberCommandService.java @@ -56,4 +56,9 @@ public MemberInfoResponseDto changeDepartment(Long memberId, ChangeDepartmentReq member.changeDepartment(department); return MemberInfoResponseDto.from(member); } + + public MemberInfoResponseDto changePasswordByAuth(String username, ChangePasswordRequestDto requestDto) { + Member member = memberRepository.findByUsername(username).orElseThrow(() -> new GeneralException(ErrorCode.MEMBER_NOT_FOUND)); + return changePassword(member.getId(), requestDto); + } }