Skip to content

Commit

Permalink
fix: vaildation code, post api annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
LAPLACE4A authored and Village-GG-Water committed Nov 3, 2024
1 parent 1fd95c0 commit db69b58
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/kert/controller/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

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.*;

import java.util.List;

@RestController
@RequestMapping("/posts")
@RequiredArgsConstructor
public class PostController {

@Autowired
private PostService postService;
private final PostService postService;

@PostMapping
public ResponseEntity<Post> createPost(@RequestBody Post post) {
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/kert/dto/LoginDTO.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.kert.dto;

import lombok.*;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class LoginDTO {
@NotNull
@Positive
private Long studentId;

@NotBlank
private String password;
}
9 changes: 8 additions & 1 deletion src/main/java/com/kert/dto/PasswordDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.NoArgsConstructor;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import jakarta.validation.constraints.Pattern;

@Data
@NoArgsConstructor
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/kert/dto/RefreshTokenRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
23 changes: 22 additions & 1 deletion src/main/java/com/kert/dto/SignUpDTO.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
}
6 changes: 5 additions & 1 deletion src/main/java/com/kert/dto/TokenResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/main/java/com/kert/service/PostService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit db69b58

Please sign in to comment.