-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathUserService.java
More file actions
30 lines (23 loc) · 945 Bytes
/
UserService.java
File metadata and controls
30 lines (23 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.loopers.domain.user;
import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
@Transactional
public User register(String userId, String email, String birth, String gender) {
userRepository.findByUserId(userId).ifPresent(user -> {
throw new CoreException(ErrorType.CONFLICT, "이미 가입된 사용자 ID 입니다.");
});
User user = new User(userId, email, birth, gender);
return userRepository.save(user);
}
@Transactional(readOnly = true)
public User findUserByUserId(String userId) {
return userRepository.findByUserId(userId).orElse(null);
}
}