[기본과제/심화과제] 3주차 JPA 활용해서 유저, 게시물 기능 구현하기#3
Open
hayounSong wants to merge 16 commits intomainfrom
Hidden character warning
The head ref may contain hidden characters: "3\uc8fc\ucc28"
Open
Conversation
2zerozu
approved these changes
May 31, 2023
| protected ApiResponseDto handleEntityNotFoundException(final EntityNotFoundException e) { | ||
| return ApiResponseDto.error(ErrorStatus.NOT_FOUND_USER); | ||
| } | ||
| } |
There was a problem hiding this comment.
보통 여기에 500에러를 넣나요 안 넣나요?! (궁금해서 물어보는 것..)
| import java.util.List; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor |
There was a problem hiding this comment.
@RequestMapping("/post") 어노테이션 달아주고 아래 맵핑에는 /create, /{id}, /search만 써도 될 것 같네요!!
아래 user도 마찬가지~
|
|
||
| @GetMapping("/user/{id}") | ||
| @ResponseStatus(HttpStatus.OK) | ||
| public ApiResponseDto<UserResponseDto> search(@PathVariable @Valid final Long id){ |
There was a problem hiding this comment.
보통 @Valid는 dto 유효성 검사할 때 쓰는 어노테이션 아닌가요..?! id에도 써준 이유가 궁금합니다!
그리고 파라미터를 상수로 받아온 이유도 궁금해요~~
Comment on lines
+23
to
+40
| @Column(nullable = false) | ||
| private String email; | ||
|
|
||
|
|
||
| @Column(nullable = false) | ||
| private String password; | ||
|
|
||
| @OneToMany(mappedBy = "created_user") | ||
| private List<Post> posts=new ArrayList<Post>(); | ||
| @Builder | ||
| public User(String nickname,String email,String password){ | ||
| this.nickname=nickname; | ||
| this.email=email; | ||
| this.password=password; | ||
| this.posts=new ArrayList<Post>(); | ||
| } | ||
|
|
||
|
|
| INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "예상치 못한 서버 에러가 발생했습니다."), | ||
| BAD_GATEWAY_EXCEPTION(HttpStatus.BAD_GATEWAY, "일시적인 에러가 발생하였습니다.\n잠시 후 다시 시도해주세요!"), | ||
| SERVICE_UNAVAILABLE_EXCEPTION(HttpStatus.SERVICE_UNAVAILABLE, "현재 점검 중입니다.\n잠시 후 다시 시도해주세요!"), | ||
| ; |
| VALIDATION_EXCEPTION(HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), | ||
| VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST, "요청값이 입력되지 않았습니다."), | ||
|
|
||
| NOT_FOUND_USER(HttpStatus.BAD_REQUEST, "검색 결과가 없습니다."), |
There was a problem hiding this comment.
NOT_FOUND면 404가 맞지 않나요?? 400으로 처리해줬네요!
Comment on lines
+1
to
+21
| spring: | ||
| datasource: | ||
| driver-class-name: com.mysql.cj.jdbc.Driver | ||
| url: jdbc:mysql://localhost:3306/sopt_32?useSSL=true&useUnicode=true&serverTimezone=Asia/Seoul | ||
| username: sopt_server | ||
| password: 1124 | ||
|
|
||
| jpa: | ||
| show-sql: true | ||
| hibernate: | ||
| ddl-auto: create | ||
| properties: | ||
| hibernate: | ||
| format_sql: true | ||
| logging: | ||
| level: | ||
| org: | ||
| hibernate: | ||
| type: | ||
| descriptor: | ||
| sql: trace No newline at end of file |
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.
🐕 과제 구현 명세
🐥 이런 점이 새로웠어요 / 어려웠어요
이런식으로, PostController를 작성해주었고, 여기서 Request 핸들링을 해주었고, 오류 처리까지 해주었습니다!
단,...서버 꿈나무인 제가 조금 헷갈렸던 부부은
세미나때와 저번 가희 코드리뷰에서 배웠던 빌더배턴을 써보려고 했고, User에서는 직접 빌더를 만들어주고, 여기서는 어노테이션을 써보려고 헀는데... 생성자를 요로코롬 선언해주는게 과연 맞을지 조오금 궁금합니다...