diff --git a/src/main/java/com/umc/dream/controller/UserController.java b/src/main/java/com/umc/dream/controller/UserController.java index a9176de..ca39796 100644 --- a/src/main/java/com/umc/dream/controller/UserController.java +++ b/src/main/java/com/umc/dream/controller/UserController.java @@ -33,4 +33,11 @@ public ApiResponse login(@RequestBody UserReques User user = userService.login(request); return ApiResponse.onSuccess(UserConverter.toLoginResultDTO(user)); } + + @Operation(summary = "아이디 중복확인 API", description = "중복이면 true, 중복이 아니면 false를 반환합니다.") + @PostMapping("/check-account") + public ApiResponse checkAccount(@RequestBody UserRequestDTO.CheckAccountRequestDto request){ + boolean isDuplicated = userService.CheckAccount(request); + return ApiResponse.onSuccess(UserConverter.toCheckAccountResultDTO(isDuplicated)); + } } diff --git a/src/main/java/com/umc/dream/converter/UserConverter.java b/src/main/java/com/umc/dream/converter/UserConverter.java index 89c9581..8beed46 100644 --- a/src/main/java/com/umc/dream/converter/UserConverter.java +++ b/src/main/java/com/umc/dream/converter/UserConverter.java @@ -21,6 +21,10 @@ public static UserResponseDTO.LoginResultDTO toLoginResultDTO(User user) { .build(); } + public static UserResponseDTO.CheckAccountResultDTO toCheckAccountResultDTO(boolean isDuplicated) { + return new UserResponseDTO.CheckAccountResultDTO(isDuplicated); + } + public static User toUser(UserRequestDTO.JoinDto joinDto) { return User.builder() .name(joinDto.getName()) diff --git a/src/main/java/com/umc/dream/dto/UserRequestDTO.java b/src/main/java/com/umc/dream/dto/UserRequestDTO.java index 03d8988..6ee6ba7 100644 --- a/src/main/java/com/umc/dream/dto/UserRequestDTO.java +++ b/src/main/java/com/umc/dream/dto/UserRequestDTO.java @@ -25,4 +25,10 @@ public static class LoginDto { @NotNull String password; } + + @Getter + public static class CheckAccountRequestDto { + @NotNull + String account; + } } diff --git a/src/main/java/com/umc/dream/dto/UserResponseDTO.java b/src/main/java/com/umc/dream/dto/UserResponseDTO.java index 688ce0b..9f460d1 100644 --- a/src/main/java/com/umc/dream/dto/UserResponseDTO.java +++ b/src/main/java/com/umc/dream/dto/UserResponseDTO.java @@ -25,4 +25,12 @@ public static class JoinResultDTO{ public static class LoginResultDTO { Long userId; } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class CheckAccountResultDTO { + boolean isDuplicated; + } } diff --git a/src/main/java/com/umc/dream/service/UserService/UserService.java b/src/main/java/com/umc/dream/service/UserService/UserService.java index e9c4249..70c85f1 100644 --- a/src/main/java/com/umc/dream/service/UserService/UserService.java +++ b/src/main/java/com/umc/dream/service/UserService/UserService.java @@ -7,4 +7,6 @@ public interface UserService { User join(UserRequestDTO.JoinDto request); User login(UserRequestDTO.LoginDto request); + + boolean CheckAccount(UserRequestDTO.CheckAccountRequestDto request); } diff --git a/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java b/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java index 4bd1b5d..a96f170 100644 --- a/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java +++ b/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java @@ -9,6 +9,8 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.Optional; + @Service @RequiredArgsConstructor public class UserServiceImpl implements UserService { @@ -37,4 +39,15 @@ public User login(UserRequestDTO.LoginDto request) { } } + @Override + public boolean CheckAccount(UserRequestDTO.CheckAccountRequestDto request) { + Optional user = userRepository.findByAccount(request.getAccount()); + + if (user.isPresent()) { // 아이디 중복 + return true; + } else { // 아이디 중복x + return false; + } + } + }