Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] refactor: request DTO Validation 추가(#462) #463

Merged
merged 13 commits into from
Oct 6, 2023
Merged

[BE] refactor: request DTO Validation 추가(#462) #463

merged 13 commits into from
Oct 6, 2023

Conversation

xxeol2
Copy link
Member

@xxeol2 xxeol2 commented Sep 26, 2023

📌 관련 이슈

✨ PR 세부 내용

@xxeol2 xxeol2 linked an issue Sep 26, 2023 that may be closed by this pull request
@xxeol2 xxeol2 added the BE 백엔드에 관련된 작업 label Sep 26, 2023
@github-actions
Copy link

github-actions bot commented Sep 26, 2023

Unit Test Results

  70 files    70 suites   12s ⏱️
195 tests 195 ✔️ 0 💤 0
198 runs  198 ✔️ 0 💤 0

Results for commit c9de21b.

♻️ This comment has been updated with latest results.

@BGuga BGuga changed the title [BE] refactor: equest DTO Validation 추가(#462) [BE] refactor: request DTO Validation 추가(#462) Sep 26, 2023
@xxeol2 xxeol2 self-assigned this Sep 26, 2023
# Conflicts:
#	backend/src/main/java/com/festago/auth/dto/LoginRequest.java
#	backend/src/main/java/com/festago/festival/dto/FestivalCreateRequest.java
@seokjin8678
Copy link
Collaborator

충돌나는거 수정했고, 예외 메시지 일괄적이게 변경했습니다!

Copy link
Collaborator

@seokjin8678 seokjin8678 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~
추가적으로 적용해야할 부분에 대해 커멘트 밑에 남기겠습니다!

Comment on lines 11 to 16
@NotNull(message = "name 은 null 일 수 없습니다.") String name,
@DateTimeFormat(iso = ISO.DATE) LocalDate startDate,
@DateTimeFormat(iso = ISO.DATE) LocalDate endDate,
@NotBlank(message = "name은 공백일 수 없습니다.") String name,
@NotNull(message = "startDate는 null 일 수 없습니다.") @DateTimeFormat(iso = ISO.DATE) LocalDate startDate,
@NotNull(message = "endDate는 null 일 수 없습니다.") @DateTimeFormat(iso = ISO.DATE) LocalDate endDate,
String thumbnail,
@NotNull(message = "schoolId는 null 일 수 없습니다.") Long schoolId
) {
@NotNull(message = "schoolId는 null 일 수 없습니다.") Long schoolId) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

검증 어노테이션이 많아 가독성이 낮아져 컨벤션을 정해야 할 것 같네요!
제 생각에는 해당 방식이 좋아보이는데 어떠신가요?

public record FestivalCreateRequest(
    @NotBlank(message = "name 은 공백일 수 없습니다.")
    String name,

    @NotNull(message = "startDate 는 null 일 수 없습니다.")
    @DateTimeFormat(iso = ISO.DATE)
    LocalDate startDate,

    @NotNull(message = "endDate 는 null 일 수 없습니다.")
    @DateTimeFormat(iso = ISO.DATE)
    LocalDate endDate,

    String thumbnail) {
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

동의보감입니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

진행시켜!

@seokjin8678
Copy link
Collaborator

일부 Contorller에 @Valid 어노테이션이 빠져 있네요!

public class StudentController {
    ...
    @PostMapping("/send-verification")
    public ResponseEntity<Void> sendEmail(@Member Long memberId,
                                          @RequestBody StudentSendMailRequest request) {
        studentService.sendVerificationMail(memberId, request);
        return ResponseEntity.ok()
            .build();
    }
    ...
}

@seokjin8678
Copy link
Collaborator

지금 GlobalExceptionHandler 클래스에서 MethodArgumentNotValidException 핸들링을 수행할 때 어떠한 필드에 값이 유효하지 않은지 알려주지 않고 "잘못된 요청입니다." 메시지만 반환해주고 있네요!
예외에서 getFieldErrors() 메서드를 통해 어떠한 검증이 실패했는지 알려주는게 좋을 것 같아요!

@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { 
    ...
    @Override
    protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException e, HttpHeaders headers,
                                                                  HttpStatusCode status, WebRequest request) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
            .body(ErrorResponse.from(ErrorCode.INVALID_REQUEST_ARGUMENT));
    }
    ...
}

@BGuga
Copy link
Member

BGuga commented Sep 30, 2023

일부 Contorller에 @Valid 어노테이션이 빠져 있네요!

public class StudentController {
    ...
    @PostMapping("/send-verification")
    public ResponseEntity<Void> sendEmail(@Member Long memberId,
                                          @RequestBody StudentSendMailRequest request) {
        studentService.sendVerificationMail(memberId, request);
        return ResponseEntity.ok()
            .build();
    }
    ...
}

@BGuga BGuga closed this Sep 30, 2023
@BGuga BGuga reopened this Sep 30, 2023
@BGuga
Copy link
Member

BGuga commented Sep 30, 2023

죄송합니다 에임 이슈로 잠시 닫았었네요 😅

@xxeol2 xxeol2 requested a review from seokjin8678 October 1, 2023 18:47
# Conflicts:
#	backend/src/main/java/com/festago/presentation/AuthController.java
Copy link
Collaborator

@carsago carsago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꿋이에요

Copy link
Collaborator

@seokjin8678 seokjin8678 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

Copy link
Member

@BGuga BGuga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

@BGuga BGuga merged commit 7667ea4 into dev Oct 6, 2023
3 checks passed
@BGuga BGuga deleted the feat/#462 branch October 6, 2023 05:33
BGuga pushed a commit that referenced this pull request Oct 17, 2023
* feat: StudentSendMailRequest validation 추가

* feat: StudentVerificateRequest validation 추가

* refactor: FestivalCreateRequest NotNull/NotBlank 제약조건 추가

* refactor: TicketValidationRequest NotNull -> NotBlank 로 변경

* refactor: LoginRequest NotNull -> NotBlank 로 변경

* feat: Request DTO Validation 추가

* refactor: 예외 메시지 일괄적이게 변경

* style: 개행 일괄 적용

* refactor: Controller의 Request Body @Valid 적용

* refactor: 상수 오타 수정

* refactor: Validation Error 메세지 자세하게 수정

---------

Co-authored-by: seokjin8678 <[email protected]>
BGuga pushed a commit that referenced this pull request Oct 17, 2023
* feat: StudentSendMailRequest validation 추가

* feat: StudentVerificateRequest validation 추가

* refactor: FestivalCreateRequest NotNull/NotBlank 제약조건 추가

* refactor: TicketValidationRequest NotNull -> NotBlank 로 변경

* refactor: LoginRequest NotNull -> NotBlank 로 변경

* feat: Request DTO Validation 추가

* refactor: 예외 메시지 일괄적이게 변경

* style: 개행 일괄 적용

* refactor: Controller의 Request Body @Valid 적용

* refactor: 상수 오타 수정

* refactor: Validation Error 메세지 자세하게 수정

---------

Co-authored-by: seokjin8678 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드에 관련된 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BE] Request DTO Validation을 추가한다.
4 participants