diff --git a/src/main/java/com/kert/controller/PostController.java b/src/main/java/com/kert/controller/PostController.java index 65d9796..f3787cc 100644 --- a/src/main/java/com/kert/controller/PostController.java +++ b/src/main/java/com/kert/controller/PostController.java @@ -2,7 +2,7 @@ import com.kert.model.Post; import com.kert.service.PostService; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -10,10 +10,10 @@ @RestController @RequestMapping("/posts") +@RequiredArgsConstructor public class PostController { - @Autowired - private PostService postService; + private final PostService postService; @PostMapping public ResponseEntity createPost(@RequestBody Post post) { diff --git a/src/main/java/com/kert/dto/LoginDTO.java b/src/main/java/com/kert/dto/LoginDTO.java index c5792a5..aac6555 100644 --- a/src/main/java/com/kert/dto/LoginDTO.java +++ b/src/main/java/com/kert/dto/LoginDTO.java @@ -1,6 +1,9 @@ package com.kert.dto; import lombok.*; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Positive; @Data @AllArgsConstructor @@ -8,6 +11,10 @@ @Getter @Setter public class LoginDTO { + @NotNull + @Positive private Long studentId; + + @NotBlank private String password; } diff --git a/src/main/java/com/kert/dto/PasswordDTO.java b/src/main/java/com/kert/dto/PasswordDTO.java index 79a56b0..5741819 100644 --- a/src/main/java/com/kert/dto/PasswordDTO.java +++ b/src/main/java/com/kert/dto/PasswordDTO.java @@ -5,6 +5,7 @@ import lombok.NoArgsConstructor; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import jakarta.validation.constraints.Pattern; @Data @NoArgsConstructor @@ -14,6 +15,12 @@ public class PasswordDTO { @NotBlank(message = "비밀번호는 필수 항목입니다.") @Size(min = 8, message = "비밀번호는 8자 이상이어야 합니다.") + @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$", + message = "비밀번호는 최소 8자 이상, 하나 이상의 대문자, 소문자, 숫자 및 특수문자가 포함되어야 합니다.") + @Pattern(regexp = "^[^'\";#-]*$", message = "비밀번호에 SQL Injection에 사용될 수 있는 문자를 포함할 수 없습니다.") private String password; + + @NotBlank(message = "이전 비밀번호는 필수 항목입니다.") + @Pattern(regexp = "^[^'\";#-]*$", message = "이전 비밀번호에 SQL Injection에 사용될 수 있는 문자를 포함할 수 없습니다.") private String oldPassword; -} \ No newline at end of file +} diff --git a/src/main/java/com/kert/dto/RefreshTokenRequest.java b/src/main/java/com/kert/dto/RefreshTokenRequest.java index 7ac908c..9d8ff74 100644 --- a/src/main/java/com/kert/dto/RefreshTokenRequest.java +++ b/src/main/java/com/kert/dto/RefreshTokenRequest.java @@ -3,12 +3,12 @@ import lombok.Data; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; -import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.NotBlank; @Data @NoArgsConstructor @AllArgsConstructor public class RefreshTokenRequest { - @NotNull + @NotBlank private String refreshToken; } diff --git a/src/main/java/com/kert/dto/SignUpDTO.java b/src/main/java/com/kert/dto/SignUpDTO.java index af25d7f..2afac37 100644 --- a/src/main/java/com/kert/dto/SignUpDTO.java +++ b/src/main/java/com/kert/dto/SignUpDTO.java @@ -1,6 +1,10 @@ package com.kert.dto; import lombok.*; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Pattern; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.Size; @Data @AllArgsConstructor @@ -9,11 +13,28 @@ @Setter public class SignUpDTO { private Long studentId; + + @NotBlank(message = "이름은 필수 항목입니다.") + @Pattern(regexp = "^[a-zA-Z0-9가-힣]*$", message = "이름에는 특수문자를 포함할 수 없습니다.") private String name; + + @NotBlank(message = "비밀번호는 필수 항목입니다.") + @Size(min = 8, message = "비밀번호는 8자 이상이어야 합니다.") + @Pattern(regexp = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$", + message = "비밀번호는 최소 8자 이상, 하나 이상의 대문자, 소문자, 숫자 및 특수문자가 포함되어야 합니다.") + @Pattern(regexp = "^[^'\";#-]*$", message = "사용할 수 없는 특수문자 입니다.") private String password; + + @NotBlank(message = "이메일은 필수 항목입니다.") + @Email(message = "유효한 이메일 주소를 입력하세요.") + @Pattern(regexp = "^[^'\";#-]*$", message = "사용할 수 없는 특수문자 입니다.") private String email; + private String profilePicture; + + @NotBlank(message = "기수는 필수 항목입니다.") private String generation; - private String major; + @NotBlank(message = "전공은 필수 항목입니다.") + private String major; } diff --git a/src/main/java/com/kert/dto/TokenResponse.java b/src/main/java/com/kert/dto/TokenResponse.java index 242298c..0fdbdce 100644 --- a/src/main/java/com/kert/dto/TokenResponse.java +++ b/src/main/java/com/kert/dto/TokenResponse.java @@ -3,11 +3,15 @@ import lombok.Data; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import jakarta.validation.constraints.NotBlank; @Data @NoArgsConstructor @AllArgsConstructor public class TokenResponse { + @NotBlank private String accessToken; + + @NotBlank private String refreshToken; -} +} \ No newline at end of file diff --git a/src/main/java/com/kert/service/PostService.java b/src/main/java/com/kert/service/PostService.java index 7def30d..441fa3d 100644 --- a/src/main/java/com/kert/service/PostService.java +++ b/src/main/java/com/kert/service/PostService.java @@ -2,17 +2,17 @@ import com.kert.model.Post; import com.kert.repository.PostRepository; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service +@RequiredArgsConstructor public class PostService { - @Autowired - private PostRepository postRepository; + private final PostRepository postRepository; public Post createPost(Post post) { return postRepository.save(post);