Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat/5] 아이디 중복확인 API 구현 #10

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/com/umc/dream/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ public ApiResponse<UserResponseDTO.LoginResultDTO> 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<UserResponseDTO.CheckAccountResultDTO> checkAccount(@RequestBody UserRequestDTO.CheckAccountRequestDto request){
boolean isDuplicated = userService.CheckAccount(request);
return ApiResponse.onSuccess(UserConverter.toCheckAccountResultDTO(isDuplicated));
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/umc/dream/converter/UserConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/umc/dream/dto/UserRequestDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ public static class LoginDto {
@NotNull
String password;
}

@Getter
public static class CheckAccountRequestDto {
@NotNull
String account;
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/umc/dream/dto/UserResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public static class JoinResultDTO{
public static class LoginResultDTO {
Long userId;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class CheckAccountResultDTO {
boolean isDuplicated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface UserService {
User join(UserRequestDTO.JoinDto request);

User login(UserRequestDTO.LoginDto request);

boolean CheckAccount(UserRequestDTO.CheckAccountRequestDto request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
Expand Down Expand Up @@ -37,4 +39,15 @@ public User login(UserRequestDTO.LoginDto request) {
}
}

@Override
public boolean CheckAccount(UserRequestDTO.CheckAccountRequestDto request) {
Optional<User> user = userRepository.findByAccount(request.getAccount());

if (user.isPresent()) { // 아이디 중복
return true;
} else { // 아이디 중복x
return false;
}
}

}
Loading