MoNew-Request-User-ID
헤더를 통해 전달됩니다.Method | Endpoint | 설명 |
---|---|---|
GET | /api/users | 계정 목록 조회 |
POST | /api/users/ | 회원가입 |
PATCH | /api/users/{userId}/role | 권한 수정 |
GET | /api/users/{userId}/profiles | 프로필 조회 |
PATCH | /api/users/{userId}/profiles | 프로필 업데이트 |
PATCH | /api/users/{userId}/password | 비밀번호 변경 |
PATCH | /api/users/{userId}/lock | 계정 잠금 상태 변경 |
API Endpoint: POST /api/users
작업 요약:
UserCreateRequest
DTO 설계 (record 기반)
@NotBlank
, @Size(min = 3, max = 50)
@NotBlank
, @Email
, @Size(max = 100)
→ 서비스 로직에서 중복 불가 처리@NotBlank
, @Size(min = 8, max = 60)
, @Pattern
(숫자, 문자, 특수문자 포함)UserDto
응답 DTO 설계 (record 기반)
id
, createdAt
, email
, name
, role
, linkedOAuthProviders
, locked
필드를 포함하여 생성된 사용자 정보를 반환합니다.Controller
→ Service
→ Repository
→ Entity
저장 순서로 진행됩니다.UserService.createUser
메서드는 이메일 중복을 검사하고, 비밀번호를 암호화(PasswordEncoder
)한 후 User
와 Profile
엔티티를 생성하여 저장합니다.UserServiceImpl
에서 userRepository.existsByEmail(String email)
을 사용하여 DB에 동일한 이메일이 있는지 확인합니다.예외 처리:
UserCreateRequest
의 @Valid
어노테이션에 의해 입력값 유효성 검증 실패 시, GlobalExceptionHandler
가 MethodArgumentNotValidException
을 처리합니다.UserServiceImpl
에서 이메일 중복이 감지되면 RestException(ErrorCode.CONFLICT, ...)
를 발생시킵니다.예외 응답 포맷 (ErrorResponse
):
// 409 Conflict 발생 시 예시
{
"exceptionName": "CONFLICT",
"message": "이미 존재하는 리소스입니다.",
"details": {
"email": "[email protected]"
}
}
사용 클래스:
UserCreateRequest
, UserDto
User
, Profile
UserRepository
, ProfileRepository
UserMapper
UserService.createUser()
, UserServiceImpl
UserController.createUser()
RestException
, ErrorCode.CONFLICT
, GlobalExceptionHandler
PasswordEncoder
GET /api/users
@PreAuthorize("hasRole('ADMIN')")
)