부산대 BE_박민재 2주차 과제 (1단계)#292
Open
minjae4650 wants to merge 15 commits intokakao-tech-campus-2nd-step2:minjae4650from
Open
부산대 BE_박민재 2주차 과제 (1단계)#292minjae4650 wants to merge 15 commits intokakao-tech-campus-2nd-step2:minjae4650from
minjae4650 wants to merge 15 commits intokakao-tech-campus-2nd-step2:minjae4650from
Conversation
- 1주차 과제 피드백 반영 - README.md 제목은 이번 과제인 위시리스트로 변경
- ID로 찾을 때, Product Not Found 이면 여러개의 상품을 동시 업데이트 하는 경우 ID가 없는 경우 앞에거는 수정이 완료되고 그 뒤에서부터는 Exception이 발생하여 뒤에거는 Handler가 바로 처리. - 따라서 이 부분만 try catch 로 뒤에 부분도 정상적으로 동작되도록 처리
- Spring Boot 프로젝트에 유효성 검사를 위한 의존성인 'org.springframework.boot:spring-boot-starter-validation'을 추가
- 불필요한 txt 삭제
- 전역 예외 처리 관리를 위해 GlobalExceptionHandler 클래스를 추가 - ProductNotFoundException 예외를 처리하여 404 NOT FOUND 상태 코드를 반환하도록 설정했습니다. - MethodArgumentNotValidException 예외를 처리하여 입력값 유효성 검사 실패 시 400 BAD REQUEST 상태 코드를 반환하도록 설정
- createProduct 메소드에 @Valid 어노테이션을 추가하여 Product 생성 시 입력값에 대한 유효성 검증을 수행
- 반환값을 ResponseEntity<Map<String, Object>> 로 통일
- Put은 모든 속성을 줘야되기 떄문에 @Valid를 통해서 유효성 검사를 하도록 수정
- "카카오" 문구가 들어간 경우 msg로 사용자에게 알림
- ForbiddenWordException 예외를 처리하는 핸들러를 GlobalExceptionHandler에 추가 - 예외 발생 시 400 BAD REQUEST 상태 코드를 반환하고, 예외 메시지를 응답 본문에 포함
- 카카오 문구가 포함된 경우 Exception을 일으킴 - 전역 Exception Handler에서 이를 처리
- 함수 새로 만드는 것 대신 applyUpdate에서 처리
- 여러개 업데이트 할 때, 에러 발생 시 뒤에 객체들은 수정안되는 것 방지
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
과제를 진행하면서 @Valid 유효성 검사에 대해서 처음 써보았습니다.
create할 때 지금 사용했지만, Patch 같은 일부만 받아와 수정하는 경우에서는 어떻게 유효성 검사를 하는지 궁금합니다.
이때는 Controller에서 검사하는 것이 아니고, Service나 Repository에서 검사하는 것이 맞는 것일까요?