From 403fe382405552a57dc35d8ce1587c7fcd683083 Mon Sep 17 00:00:00 2001 From: jinho7 <69239293+jinho7@users.noreply.github.com> Date: Fri, 10 May 2024 03:08:55 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20Account=20->?= =?UTF-8?q?=20User=20=EB=AA=85=EC=B9=AD=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SettingController.java | 2 +- ...ntsController.java => UserController.java} | 40 +++++++++---------- ...countConverter.java => UserConverter.java} | 6 +-- .../{AccountReqDto.java => UserReqDto.java} | 6 +-- .../{AccountResDto.java => UserResDto.java} | 2 +- .../jwt/filter/JwtAuthenticationFilter.java | 6 +-- ...{AccountsService.java => UserService.java} | 10 ++--- 7 files changed, 35 insertions(+), 37 deletions(-) rename user-service/src/main/java/com/waither/userservice/controller/{AccountsController.java => UserController.java} (67%) rename user-service/src/main/java/com/waither/userservice/dto/converter/{AccountConverter.java => UserConverter.java} (71%) rename user-service/src/main/java/com/waither/userservice/dto/request/{AccountReqDto.java => UserReqDto.java} (93%) rename user-service/src/main/java/com/waither/userservice/dto/response/{AccountResDto.java => UserResDto.java} (63%) rename user-service/src/main/java/com/waither/userservice/service/{AccountsService.java => UserService.java} (96%) diff --git a/user-service/src/main/java/com/waither/userservice/controller/SettingController.java b/user-service/src/main/java/com/waither/userservice/controller/SettingController.java index 411c7ca9..1ce43a24 100644 --- a/user-service/src/main/java/com/waither/userservice/controller/SettingController.java +++ b/user-service/src/main/java/com/waither/userservice/controller/SettingController.java @@ -98,7 +98,7 @@ public ApiResponse updateRegionReport(@AuthUser User user, @RequestBody return ApiResponse.onSuccess("직장 지역 레포트 알림 설정이 " + regionReportDto.regionReport() + "로 바뀌었습니다."); } - // ReadOnly (GET) + /* --------- ReadOnly (GET) --------- */ @GetMapping("/custom") public ApiResponse getUserCustom(@AuthUser User user) { return ApiResponse.onSuccess(settingQueryService.getUserCustom(user)); diff --git a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java b/user-service/src/main/java/com/waither/userservice/controller/UserController.java similarity index 67% rename from user-service/src/main/java/com/waither/userservice/controller/AccountsController.java rename to user-service/src/main/java/com/waither/userservice/controller/UserController.java index 023e0395..f1cde08f 100644 --- a/user-service/src/main/java/com/waither/userservice/controller/AccountsController.java +++ b/user-service/src/main/java/com/waither/userservice/controller/UserController.java @@ -1,10 +1,10 @@ package com.waither.userservice.controller; -import com.waither.userservice.dto.request.AccountReqDto; +import com.waither.userservice.dto.request.UserReqDto; import com.waither.userservice.entity.User; import com.waither.userservice.global.annotation.AuthUser; import com.waither.userservice.jwt.dto.JwtDto; -import com.waither.userservice.service.AccountsService; +import com.waither.userservice.service.UserService; import com.waither.userservice.global.response.ApiResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; @@ -17,14 +17,14 @@ @RequiredArgsConstructor @RestController @RequestMapping(value = "/") -public class AccountsController { +public class UserController { - private final AccountsService accountsService; + private final UserService userService; // 회원가입 @PostMapping("/signup") - public ResponseEntity> register(@Valid @RequestBody AccountReqDto.RegisterRequestDto requestDto) { - accountsService.signup(requestDto); + public ResponseEntity> register(@Valid @RequestBody UserReqDto.SignUpRequestDto requestDto) { + userService.signup(requestDto); // SignUp 때만 201 Created 사용 return ResponseEntity .status(HttpStatus.CREATED) @@ -36,7 +36,7 @@ public ResponseEntity> register(@Valid @RequestBody AccountR // Jwt 토큰 재발급 @GetMapping("/reissue") public ApiResponse reissueToken(@RequestHeader("RefreshToken") String refreshToken) { - JwtDto jwtDto = accountsService.reissueToken(refreshToken); + JwtDto jwtDto = userService.reissueToken(refreshToken); return ApiResponse.onSuccess(jwtDto); } @@ -44,47 +44,47 @@ public ApiResponse reissueToken(@RequestHeader("RefreshToken") String re // 이메일에 인증번호 보내기 @GetMapping("/emails/submit-authcode") public ApiResponse submitAuthCode(@RequestBody String email) { - accountsService.sendAuthCodeToEmail(email); + userService.sendAuthCodeToEmail(email); return ApiResponse.onSuccess("인증번호 전송에 성공했습니다."); } // 이메일 인증하기 @PostMapping("/emails/verifications") - public ApiResponse verificationEmail(@RequestBody AccountReqDto.EmailVerificationDto verificationDto) { - accountsService.verifyCode(verificationDto.email(), verificationDto.authCode()); + public ApiResponse verificationEmail(@RequestBody UserReqDto.EmailVerificationDto verificationDto) { + userService.verifyCode(verificationDto.email(), verificationDto.authCode()); return ApiResponse.onSuccess("이메일 인증에 성공했습니다."); } // 임시 비밀번호 발급 @GetMapping("/emails/temporary-password") public ApiResponse submitTemporaryPassword(@RequestParam String email) { - accountsService.checkUserExists(email); - String tempPassword = accountsService.sendTempPassword(email); - accountsService.changeToTempPassword(email, tempPassword); + userService.checkUserExists(email); + String tempPassword = userService.sendTempPassword(email); + userService.changeToTempPassword(email, tempPassword); return ApiResponse.onSuccess("인증번호 전송에 성공했습니다."); } // 닉네임 변경 @PatchMapping("/update-nickname") public ApiResponse updateNickname(@AuthUser User user, - @RequestBody AccountReqDto.NicknameDto nicknameDto) { - accountsService.updateNickname(user, nicknameDto.nickname()); + @RequestBody UserReqDto.NicknameDto nicknameDto) { + userService.updateNickname(user, nicknameDto.nickname()); return ApiResponse.onSuccess("닉네임이 " + nicknameDto.nickname() + "로 바뀌었습니다."); } // 비밀번호 확인 @PostMapping("/password-check") public ApiResponse passwordCheckEmail(@AuthUser User user, - @RequestBody AccountReqDto.PasswordCheckDto passwordCheckDto) { - accountsService.checkPassword(user, passwordCheckDto.password()); + @RequestBody UserReqDto.PasswordCheckDto passwordCheckDto) { + userService.checkPassword(user, passwordCheckDto.password()); return ApiResponse.onSuccess("비밀번호가 확인되었습니다."); } // 비밀번호 변경 @PatchMapping("/update-password") public ApiResponse updatePassword(@AuthUser User user, - @Valid @RequestBody AccountReqDto.UpdatePasswordDto updatePasswordDto) { - accountsService.updatePassword(user, updatePasswordDto.password()); + @Valid @RequestBody UserReqDto.UpdatePasswordDto updatePasswordDto) { + userService.updatePassword(user, updatePasswordDto.password()); return ApiResponse.onSuccess("비밀번호가 변경되었습니다."); } @@ -92,7 +92,7 @@ public ApiResponse updatePassword(@AuthUser User user, // Todo : soft delete로 변경 고려 @DeleteMapping("/delete") public ApiResponse deleteUser(@AuthUser User user) { - accountsService.deleteUser(user); + userService.deleteUser(user); return ApiResponse.onSuccess(user.getEmail() + "님의 계정이 성공적으로 탈퇴되었습니다."); } } diff --git a/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java b/user-service/src/main/java/com/waither/userservice/dto/converter/UserConverter.java similarity index 71% rename from user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java rename to user-service/src/main/java/com/waither/userservice/dto/converter/UserConverter.java index 9cbef719..086f770f 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/converter/AccountConverter.java +++ b/user-service/src/main/java/com/waither/userservice/dto/converter/UserConverter.java @@ -1,12 +1,12 @@ package com.waither.userservice.dto.converter; -import com.waither.userservice.dto.request.AccountReqDto; +import com.waither.userservice.dto.request.UserReqDto; import com.waither.userservice.entity.User; import com.waither.userservice.entity.type.UserStatus; -public class AccountConverter { +public class UserConverter { - public static User toUser(AccountReqDto.RegisterRequestDto requestDto, String encodedPw) { + public static User toUser(UserReqDto.SignUpRequestDto requestDto, String encodedPw) { return User.builder() .email(requestDto.email()) .password(encodedPw) diff --git a/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java b/user-service/src/main/java/com/waither/userservice/dto/request/UserReqDto.java similarity index 93% rename from user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java rename to user-service/src/main/java/com/waither/userservice/dto/request/UserReqDto.java index 6c44a428..6e0bfe64 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/request/AccountReqDto.java +++ b/user-service/src/main/java/com/waither/userservice/dto/request/UserReqDto.java @@ -1,12 +1,10 @@ package com.waither.userservice.dto.request; -import com.waither.userservice.entity.User; -import com.waither.userservice.entity.type.UserStatus; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Pattern; import jakarta.validation.constraints.Size; -public class AccountReqDto { +public class UserReqDto { public record LoginRequestDto( @NotBlank(message = "[ERROR] 이메일 입력은 필수입니다.") @Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "[ERROR] 이메일 형식에 맞지 않습니다.") @@ -19,7 +17,7 @@ public record LoginRequestDto( ) { } // 로그인과 같은 형식이지만, 확장성(회원가입 할 떄 추가 정보를 받을 수도 있음)을 위해 나누어 놓았습니다. - public record RegisterRequestDto( + public record SignUpRequestDto( @NotBlank(message = "[ERROR] 이메일 입력은 필수입니다.") @Pattern(regexp = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,6}$", message = "[ERROR] 이메일 형식에 맞지 않습니다.") String email, diff --git a/user-service/src/main/java/com/waither/userservice/dto/response/AccountResDto.java b/user-service/src/main/java/com/waither/userservice/dto/response/UserResDto.java similarity index 63% rename from user-service/src/main/java/com/waither/userservice/dto/response/AccountResDto.java rename to user-service/src/main/java/com/waither/userservice/dto/response/UserResDto.java index 774f4d9f..e957011f 100644 --- a/user-service/src/main/java/com/waither/userservice/dto/response/AccountResDto.java +++ b/user-service/src/main/java/com/waither/userservice/dto/response/UserResDto.java @@ -1,5 +1,5 @@ package com.waither.userservice.dto.response; -public class AccountResDto { +public class UserResDto { } diff --git a/user-service/src/main/java/com/waither/userservice/jwt/filter/JwtAuthenticationFilter.java b/user-service/src/main/java/com/waither/userservice/jwt/filter/JwtAuthenticationFilter.java index b5455169..5527a2e9 100644 --- a/user-service/src/main/java/com/waither/userservice/jwt/filter/JwtAuthenticationFilter.java +++ b/user-service/src/main/java/com/waither/userservice/jwt/filter/JwtAuthenticationFilter.java @@ -1,7 +1,7 @@ package com.waither.userservice.jwt.filter; import com.fasterxml.jackson.databind.ObjectMapper; -import com.waither.userservice.dto.request.AccountReqDto; +import com.waither.userservice.dto.request.UserReqDto; import com.waither.userservice.global.response.ApiResponse; import com.waither.userservice.jwt.dto.JwtDto; import com.waither.userservice.jwt.util.HttpResponseUtil; @@ -36,9 +36,9 @@ public Authentication attemptAuthentication(HttpServletRequest request, HttpServ // request에 있는 username과 password를 파싱해서 자바 Object로 받기 ObjectMapper om = new ObjectMapper(); - AccountReqDto.LoginRequestDto loginRequestDto; + UserReqDto.LoginRequestDto loginRequestDto; try { - loginRequestDto = om.readValue(request.getInputStream(), AccountReqDto.LoginRequestDto.class); + loginRequestDto = om.readValue(request.getInputStream(), UserReqDto.LoginRequestDto.class); } catch (IOException e) { throw new AuthenticationServiceException("Error of request body."); } diff --git a/user-service/src/main/java/com/waither/userservice/service/AccountsService.java b/user-service/src/main/java/com/waither/userservice/service/UserService.java similarity index 96% rename from user-service/src/main/java/com/waither/userservice/service/AccountsService.java rename to user-service/src/main/java/com/waither/userservice/service/UserService.java index ff385b33..9a019fe1 100644 --- a/user-service/src/main/java/com/waither/userservice/service/AccountsService.java +++ b/user-service/src/main/java/com/waither/userservice/service/UserService.java @@ -1,7 +1,7 @@ package com.waither.userservice.service; -import com.waither.userservice.dto.converter.AccountConverter; -import com.waither.userservice.dto.request.AccountReqDto; +import com.waither.userservice.dto.converter.UserConverter; +import com.waither.userservice.dto.request.UserReqDto; import com.waither.userservice.entity.Region; import com.waither.userservice.entity.Setting; import com.waither.userservice.entity.User; @@ -30,7 +30,7 @@ @RequiredArgsConstructor @Transactional @Service -public class AccountsService { +public class UserService { private final UserRepository userRepository; private final SettingRepository settingRepository; @@ -46,13 +46,13 @@ public class AccountsService { private long authCodeExpirationMillis; // 회원가입 - public void signup(AccountReqDto.RegisterRequestDto requestDto) { + public void signup(UserReqDto.SignUpRequestDto requestDto) { // if (!verifiedAccounts(requestDto.email())) { // throw new CustomException(ErrorCode.INVALID_Account); // } // 비밀번호 인코딩 String encodedPw = passwordEncoder.encode(requestDto.password()); - User newUser = AccountConverter.toUser(requestDto, encodedPw); + User newUser = UserConverter.toUser(requestDto, encodedPw); // Setting을 기본값으로 설정 Setting defaultSetting = Setting.builder()