issue # UserService 회원가입 로직 구현 중
This commit is contained in:
@@ -1,8 +1,45 @@
|
||||
package com.baekyangdan.scheduler.service.user;
|
||||
|
||||
import com.baekyangdan.scheduler.repository.user.UserRepository;
|
||||
import com.baekyangdan.scheduler.request.user.UserRequest;
|
||||
import com.baekyangdan.scheduler.utils.converter.PasswordConverter;
|
||||
import com.baekyangdan.scheduler.utils.validation.UserValidation;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
private final PasswordConverter passwordConverter;
|
||||
|
||||
public UserService(UserRepository userRepository, passwordConverter passwordConverter) {
|
||||
this.userRepository = userRepository;
|
||||
this.passwordConverter = passwordConverter;
|
||||
}
|
||||
|
||||
// 회원가입 로직
|
||||
public UserEntity signUp(UserRequest.SignUp data) throws Exception {
|
||||
// 1. 요청받은 데이터가 회원가입 양식을 준수하는지 검사한다.
|
||||
// 1-1. 회원가입 양식에 맞지 않는 데이터가 있을 경우, validateSignUpForm 함수 내에서 예외를 던져 함수 동작 중단
|
||||
UserValidation.validateSignUpForm(data);
|
||||
|
||||
// 2. data 안의 평문 비밀번호 암호화
|
||||
String encodedPassword = passwordConverter.encode(data.getPassword());
|
||||
|
||||
// 3. data 를 UserEntity 형식으로 build
|
||||
UserEntity user = UserEntity
|
||||
.builder()
|
||||
.id(data.getId())
|
||||
.email(data.getEmail())
|
||||
.name(data.getName())
|
||||
.nickname(data.getNickname())
|
||||
.password(encodedPassword)
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build();
|
||||
|
||||
// 4. build 된 entity를 UserRepository.save 로 DB에 저장
|
||||
return userRepositry.save(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,25 @@
|
||||
package com.baekyangdan.scheduler.utils.validation;
|
||||
|
||||
import jaav.util.regex.Pattern;
|
||||
import java.util.regex.Matcher;
|
||||
|
||||
public class BaseValidation {
|
||||
private String emailRegExp = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{1,}$"
|
||||
private final Pattern emailPattern = Pattern.compile("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{1,}$");
|
||||
private final Pattern phoneNumberPattern = Pattern.compile("^010-\d{4}-\d{4}$");
|
||||
|
||||
protected static boolean matchEmailPattern(String email) {
|
||||
if (validateStringEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return emailPattern.matcher(email);
|
||||
}
|
||||
|
||||
protected static boolean matchPhoneNumberPattern(String phoneNumber) {
|
||||
if (validateStringEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return phoneNumberPattern.matcher(phoneNumber);
|
||||
}
|
||||
|
||||
protected static boolean validateStringEmpty(String value) {
|
||||
if (value == null) {
|
||||
|
||||
Reference in New Issue
Block a user