Skip to content

Commit

Permalink
Merge pull request #10 from Hackathon0704/feat/5
Browse files Browse the repository at this point in the history
[feat/5] 아이디 중복확인 API 구현
  • Loading branch information
yslle authored Jul 4, 2024
2 parents 002dab3 + e76df94 commit 14fed47
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
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;
}
}

}

0 comments on commit 14fed47

Please sign in to comment.