-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat] BeanValid Exception 기능 추가 & Swagger API 명세 작성
- Loading branch information
Showing
16 changed files
with
97 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/main/java/com/jiyunio/todolist/category/GetCategoryDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/jiyunio/todolist/customError/CustomException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 23 additions & 1 deletion
24
src/main/java/com/jiyunio/todolist/customError/CustomExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
package com.jiyunio.todolist.customError; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ControllerAdvice | ||
public class CustomExceptionHandler { | ||
@ExceptionHandler(CustomException.class) | ||
protected ResponseEntity<ErrorDTO> handleCustomException(CustomException e){ | ||
protected ResponseEntity<ErrorDTO> handleCustomException(CustomException e) { | ||
return ErrorDTO.toResponseEntity(e); | ||
} | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
protected ResponseEntity<List<ErrorDTO>> beanValidationException(MethodArgumentNotValidException e) { | ||
List<FieldError> list = e.getBindingResult().getFieldErrors(); | ||
List<ErrorDTO> responseDTOList = new ArrayList<>(); | ||
|
||
for (FieldError error : list) { | ||
ErrorDTO errorDTO = ErrorDTO.builder() | ||
.code("400_Bad_Request") | ||
.msg(error.getDefaultMessage()) | ||
.build(); | ||
|
||
responseDTOList.add(errorDTO); | ||
} | ||
return new ResponseEntity<>(responseDTOList, HttpStatus.BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
package com.jiyunio.todolist.customError; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/jiyunio/todolist/member/dto/ChangeUserPwDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
package com.jiyunio.todolist.member.dto; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Schema(description = "회원 비밀번호 수정") | ||
public class ChangeUserPwDTO { | ||
@NotBlank(message = "비밀번호를 입력하세요.") | ||
@Schema(description = "회원 비밀번호") | ||
private String userPw; | ||
|
||
@NotBlank(message = "변경 비밀번호를 입력하세요.") | ||
@Pattern(regexp = "(?=.*[0-9])(?=.*[a-zA-Z])(?=.*\\W)(?=\\S+$).{8,16}") | ||
@Schema(description = "회원 수정 비밀번호", example = "qwer1234!") | ||
private String changePw; | ||
|
||
@NotBlank(message = "확인 비밀번호를 입력하세요.") | ||
@Schema(description = "회원 수정 확인 비밀번호") | ||
private String confirmChangePw; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.