-
Notifications
You must be signed in to change notification settings - Fork 13
[Spring Core] 배종연 과제 제출합니다. #9
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
Open
jybae1226
wants to merge
18
commits into
BCSDLab-Edu:main
Choose a base branch
from
jybae1226:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8d74ce6
예외 코드 추가_1
jybae1226 d6b1532
예외 처리 과제_3
jybae1226 fb97f40
예외 처리 과제_4
jybae1226 53203cc
예외 처리 과제_4
jybae1226 93d9831
비번 숨김
jybae1226 aafcab8
비번 숨김
jybae1226 bc661d9
업데이트 1
jybae1226 e9daf1c
jpa 의존성 추가
jybae1226 ace4f38
엔티티 클래스 정의
jybae1226 06ce264
Jpa 클래스 선언
jybae1226 5dc73bf
Jdbc 사용 중지
jybae1226 83db988
Jdbc 사용 중지
jybae1226 951bd22
연관관계 추가
jybae1226 91256e3
안쓰는 코드 주석처리
jybae1226 2ea8215
Jpa 리포지토리 상속 추가
jybae1226 c7ba582
Jpa 리포지토리 상속 추가
jybae1226 dead082
서비스 변경
jybae1226 c9fd11b
오류수정
jybae1226 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Binary file not shown.
Empty 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class ArticleExist extends RuntimeException{ | ||
| public ArticleExist(String message) { | ||
| super(message); | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/demo/Exception/ArticleNotFound.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class ArticleNotFound extends RuntimeException { | ||
| public ArticleNotFound(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class BoardNotFound extends RuntimeException { | ||
| public BoardNotFound(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class EmailExist extends RuntimeException { | ||
| public EmailExist(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public enum ErrorCode { | ||
|
|
||
| Article_Not_Found(404,"NOT_FOUND","게시물을 찾을 수 없습니다."), | ||
| Board_Not_Found(404,"NOT_FOUND","게시판을 찾을 수 없습니다."), | ||
| Member_Not_Found(404,"NOT_FOUND","사용자를 찾을 수 없습니다."), | ||
|
|
||
| Email_Exist(409,"Exist","이미 이메일이 존재합니다."), | ||
| Fail_Member(400,"FAIL","사용자를 참조할 수 없습니다."), | ||
| Fail_Board(400,"FAIL","게시판을 참조할 수 없습니다."), | ||
|
|
||
| Null_Exist(400,"NULL","빈(Null) 값이 존재합니다."), | ||
|
|
||
| Remain_Article(400,"REMAIN","게시물이 남아있습니다."); | ||
|
|
||
| private final int code_id; | ||
| private final String code; | ||
| private final String message; | ||
|
|
||
| ErrorCode(int code_id, String code, String message) { | ||
| this.code_id = code_id; | ||
| this.code = code; | ||
| this.message = message; | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/demo/Exception/ErrorResponse.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Getter | ||
| public class ErrorResponse { | ||
| private final LocalDateTime timestamp=LocalDateTime.now(); | ||
| private int code_id; | ||
| private String code; | ||
| private String message; | ||
|
|
||
| public ErrorResponse(ErrorCode errorCode) { | ||
| this.code_id = errorCode.getCode_id(); | ||
| this.code = errorCode.getCode(); | ||
| this.message = errorCode.getMessage(); | ||
| } | ||
|
|
||
| public ErrorResponse(ErrorCode errorCode, String message) { | ||
| this.code_id = errorCode.getCode_id(); | ||
| this.code = errorCode.getCode(); | ||
| this.message = message; | ||
| } | ||
|
Comment on lines
+14
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여러 생성자를 사용한다면 정적 팩토리 메서드로 대체해보는 건 어떻게 생각하세요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 정적 팩토리 메소드라는 용어가 익숙하지 않아서 정적 팩토리 메소드에 대해 한번 공부하고 긍정적으로 고려해보겠습니다. |
||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class FailBoard extends RuntimeException{ | ||
| public FailBoard(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class FailMember extends RuntimeException{ | ||
| public FailMember(String message) { | ||
| super(message); | ||
| } | ||
| } |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/example/demo/Exception/GlobalExceptionHandler.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
|
||
| @RestControllerAdvice | ||
| public class GlobalExceptionHandler { | ||
|
|
||
| @ExceptionHandler(ArticleNotFound.class) | ||
| public ResponseEntity<ErrorResponse> handleArticleNotFound(ArticleNotFound articleNotFound) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Article_Not_Found); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(BoardNotFound.class) | ||
| public ResponseEntity<ErrorResponse> handleBoardNotFound(BoardNotFound boardNotFound) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Board_Not_Found); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(MemberNotFound.class) | ||
| public ResponseEntity<ErrorResponse> handleMemberNotFound(MemberNotFound memberNotFound) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Member_Not_Found); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(EmailExist.class) | ||
| public ResponseEntity<ErrorResponse> handleEmailExist(EmailExist emailExist) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Email_Exist); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(FailMember.class) | ||
| public ResponseEntity<ErrorResponse> handleFailMember(FailMember failMember) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Fail_Member); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(FailBoard.class) | ||
| public ResponseEntity<ErrorResponse> handleFailBoard(FailBoard failBoard) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Fail_Board); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(NullExist.class) | ||
| public ResponseEntity<ErrorResponse> handleNullExist(NullExist nullExist) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Null_Exist); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
|
|
||
| @ExceptionHandler(ArticleExist.class) | ||
| public ResponseEntity<ErrorResponse> handleArticleExist(ArticleExist articleExist) { | ||
| ErrorResponse response=new ErrorResponse(ErrorCode.Remain_Article); | ||
| return ResponseEntity.status(response.getCode_id()).body(response); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class MemberNotFound extends RuntimeException { | ||
| public MemberNotFound(String message) { | ||
| super(message); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.example.demo.Exception; | ||
|
|
||
| public class NullExist extends RuntimeException{ | ||
| public NullExist(String message) { | ||
| super(message); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
롬복을 도입한 이유와 도입할 때 어떤 점을 고려했는지 궁금합니다
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Getter와 @Setter를 사용하려고 도입했는데 직접 get과 set을 짜서 도입만 하고 따로 사용은 안했습니다