์ผ์ N : ์ ์ 1
๋๊ธ N : ์ผ์ 1
- ๋์ผํ ์ด๋ฉ์ผ๋ก ๊ฐ์ -> email์ uniqueํ๊ฒ
@Email //import jakarta.validation.constraints.Email;
@Column(nullable = false, unique = true)
private String email;
// ์ ์ ์์ฑ
public SignUpResponseDto signUp(String email, String password, String userName) {
if (userRepository.findByEmail(email) != null) {
throw new RuntimeException("์ด๋ฏธ ์กด์ฌํ๋ ์ด๋ฉ์ผ์
๋๋ค.");
}
User user = new User(email, password, userName);
User savedUser = userRepository.save(user); // Repository์ ์ ์ฅ
return new SignUpResponseDto(savedUser);
}
- ๊ทธ ์ธ, @NoBlank @Size ๋ฑ
// ์์ 1 TodoRequest
@Getter
public class TodoRequestDto {
@NotNull
@Size(min = 1, max = 20)
private final String title;
@Size(max = 300)
private final String contents;
public TodoRequestDto(String title, String contents) {
this.title = title;
this.contents = contents;
}
}
// ์์ 2 LoginRequest
@Getter
public class LoginRequestDto {
// ์ด๋ฉ์ผ๊ณผ ๋น๋ฐ๋ฒํธ๋ก ๋ก๊ทธ์ธ
@NotBlank
@Email(message = "ํ์ : abc@naver.com")
private final String email;
@NotBlank
@Pattern(regexp = "^(?=.*[a-zA-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,64}$")
@Size(min = 8, max = 64)
private final String password;
public LoginRequestDto(String email, String password) {
this.email = email;
this.password = password;
}
}
- ํ์ด์ง ๋ฒํธ์ ํ์ด์ง ํฌ๊ธฐ๋ฅผ ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ก ์ ๋ฌ (ํ์ด์ง ๋ํดํธ ํฌ๊ธฐ๋ 10)
- ํ ์ผ ์ ๋ชฉ, ํ ์ผ ๋ด์ฉ, ๋๊ธ ๊ฐ์, ์ผ์ ์์ฑ์ผ, ์ผ์ ์์ ์ผ, ์ผ์ ์์ฑ ์ ์ ๋ช
- ์ผ์ ์์ ์ผ์ ๊ธฐ์ค์ผ๋ก ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ