Skip to content

Commit

Permalink
♻️ refactor: Account -> User 명칭 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jinho7 committed May 9, 2024
1 parent e8e6663 commit 403fe38
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public ApiResponse<String> updateRegionReport(@AuthUser User user, @RequestBody
return ApiResponse.onSuccess("직장 지역 레포트 알림 설정이 " + regionReportDto.regionReport() + "로 바뀌었습니다.");
}

// ReadOnly (GET)
/* --------- ReadOnly (GET) --------- */
@GetMapping("/custom")
public ApiResponse<SettingResDto.CustomDto> getUserCustom(@AuthUser User user) {
return ApiResponse.onSuccess(settingQueryService.getUserCustom(user));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<ApiResponse<String>> register(@Valid @RequestBody AccountReqDto.RegisterRequestDto requestDto) {
accountsService.signup(requestDto);
public ResponseEntity<ApiResponse<String>> register(@Valid @RequestBody UserReqDto.SignUpRequestDto requestDto) {
userService.signup(requestDto);
// SignUp 때만 201 Created 사용
return ResponseEntity
.status(HttpStatus.CREATED)
Expand All @@ -36,63 +36,63 @@ public ResponseEntity<ApiResponse<String>> register(@Valid @RequestBody AccountR
// Jwt 토큰 재발급
@GetMapping("/reissue")
public ApiResponse<JwtDto> reissueToken(@RequestHeader("RefreshToken") String refreshToken) {
JwtDto jwtDto = accountsService.reissueToken(refreshToken);
JwtDto jwtDto = userService.reissueToken(refreshToken);
return ApiResponse.onSuccess(jwtDto);

}

// 이메일에 인증번호 보내기
@GetMapping("/emails/submit-authcode")
public ApiResponse<String> submitAuthCode(@RequestBody String email) {
accountsService.sendAuthCodeToEmail(email);
userService.sendAuthCodeToEmail(email);
return ApiResponse.onSuccess("인증번호 전송에 성공했습니다.");
}

// 이메일 인증하기
@PostMapping("/emails/verifications")
public ApiResponse<String> verificationEmail(@RequestBody AccountReqDto.EmailVerificationDto verificationDto) {
accountsService.verifyCode(verificationDto.email(), verificationDto.authCode());
public ApiResponse<String> verificationEmail(@RequestBody UserReqDto.EmailVerificationDto verificationDto) {
userService.verifyCode(verificationDto.email(), verificationDto.authCode());
return ApiResponse.onSuccess("이메일 인증에 성공했습니다.");
}

// 임시 비밀번호 발급
@GetMapping("/emails/temporary-password")
public ApiResponse<String> 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<String> 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<String> 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<String> 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("비밀번호가 변경되었습니다.");
}


// Todo : soft delete로 변경 고려
@DeleteMapping("/delete")
public ApiResponse<String> deleteUser(@AuthUser User user) {
accountsService.deleteUser(user);
userService.deleteUser(user);
return ApiResponse.onSuccess(user.getEmail() + "님의 계정이 성공적으로 탈퇴되었습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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] 이메일 형식에 맞지 않습니다.")
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.waither.userservice.dto.response;

public class AccountResDto {
public class UserResDto {

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,7 +30,7 @@
@RequiredArgsConstructor
@Transactional
@Service
public class AccountsService {
public class UserService {

private final UserRepository userRepository;
private final SettingRepository settingRepository;
Expand All @@ -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()
Expand Down

0 comments on commit 403fe38

Please sign in to comment.