-
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.
Merge branch 'develop' into #14/record
- Loading branch information
Showing
25 changed files
with
444 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/main/java/com/todaysgym/todaysgym/config/ControllerAdvice.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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.todaysgym.todaysgym.config; | ||
|
||
import com.todaysgym.todaysgym.config.exception.BaseException; | ||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import com.todaysgym.todaysgym.config.exception.errorCode.GlobalErrorCode; | ||
import com.todaysgym.todaysgym.config.response.ExceptionResponse; | ||
import java.util.List; | ||
import org.springframework.validation.FieldError; | ||
import org.springframework.web.HttpMediaTypeNotSupportedException; | ||
import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
import org.springframework.web.servlet.NoHandlerFoundException; | ||
|
||
@RestControllerAdvice | ||
public class ControllerAdvice { | ||
|
||
@ExceptionHandler(BaseException.class) | ||
public ExceptionResponse handleBaseException(BaseException e) { | ||
ExceptionResponse exceptionResponse = new ExceptionResponse(e.getErrorCode(), | ||
e.getMessage()); | ||
return exceptionResponse; | ||
} | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ExceptionResponse handleException(MethodArgumentNotValidException e) { | ||
String detailMessage = extractMessage(e.getBindingResult().getFieldErrors()); | ||
return convert(GlobalErrorCode.NOT_VALID_ARGUMENT_ERROR, detailMessage); | ||
} | ||
|
||
private String extractMessage(List<FieldError> fieldErrors) { | ||
StringBuilder builder = new StringBuilder(); | ||
fieldErrors.forEach((error) -> { | ||
builder.append("["); | ||
builder.append(error.getField()); | ||
builder.append(": "); | ||
builder.append(error.getDefaultMessage()); | ||
builder.append(" || input value: "); | ||
builder.append("]"); | ||
builder.append(System.lineSeparator()); | ||
}); | ||
return builder.toString(); | ||
} | ||
|
||
@ExceptionHandler(NoHandlerFoundException.class) | ||
public ExceptionResponse handleNoHandlerFoundException() { | ||
return convert(GlobalErrorCode.NOT_SUPPORTED_URI_ERROR); | ||
} | ||
|
||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class) | ||
public ExceptionResponse handleMethodNotSupportedException() { | ||
return convert(GlobalErrorCode.NOT_SUPPORTED_METHOD_ERROR); | ||
} | ||
|
||
@ExceptionHandler(HttpMediaTypeNotSupportedException.class) | ||
public ExceptionResponse handleMediaTypeNotSupportedException() { | ||
return convert(GlobalErrorCode.NOT_SUPPORTED_MEDIA_TYPE_ERROR); | ||
} | ||
|
||
@ExceptionHandler(RuntimeException.class) | ||
public ExceptionResponse handleRuntimeException() { | ||
return convert(GlobalErrorCode.SERVER_ERROR); | ||
} | ||
|
||
private ExceptionResponse convert(ErrorCode e) { | ||
ExceptionResponse exceptionRes = new ExceptionResponse(e.getErrorCode(), e.getMessage()); | ||
return exceptionRes; | ||
} | ||
|
||
private ExceptionResponse convert(ErrorCode e, String detailMessage) { | ||
ExceptionResponse exceptionRes = new ExceptionResponse(e.getErrorCode(), detailMessage); | ||
return exceptionRes; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/todaysgym/todaysgym/config/exception/BaseException.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.todaysgym.todaysgym.config.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class BaseException extends RuntimeException { | ||
|
||
private final String errorCode; | ||
private final String message; | ||
|
||
public BaseException(ErrorCode code) { | ||
errorCode = code.getErrorCode(); | ||
message = code.getMessage(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/todaysgym/todaysgym/config/exception/ErrorCode.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.todaysgym.todaysgym.config.exception; | ||
|
||
public interface ErrorCode { | ||
|
||
String getErrorCode(); | ||
|
||
String getMessage(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/AuthErrorCode.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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum AuthErrorCode implements ErrorCode { | ||
EMPTY_JWT("AUTH_001", "JWT를 입력해주세요."), | ||
INVALID_JWT("AUTH_002", "유효하지 않은 JWT입니다."), | ||
EXPIRED_MEMBER_JWT("AUTH_003", "만료된 JWT입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/CategoryErrorCode.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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum CategoryErrorCode { | ||
EMPTY_CATEGORY("CATEGORY_001", "존재하지 않는 카테고리입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/CommentErrorCode.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum CommentErrorCode implements ErrorCode { | ||
EMPTY_COMMENT("COMMENT_001", "존재하지 않는 댓글입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/GlobalErrorCode.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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum GlobalErrorCode implements ErrorCode { | ||
NOT_VALID_ARGUMENT_ERROR("GLOBAL_001", "올바른 argument를 입력해주세요."), | ||
NOT_SUPPORTED_URI_ERROR("GLOBAL_002", "올바른 URI로 접근해주세요."), | ||
NOT_SUPPORTED_METHOD_ERROR("GLOBAL_003", "지원하지 않는 Method입니다."), | ||
NOT_SUPPORTED_MEDIA_TYPE_ERROR("GLOBAL_004", "지원하지 않는 Media type입니다."), | ||
SERVER_ERROR("GLOBAL_005", "서버와의 연결에 실패하였습니다."), | ||
; | ||
|
||
private final String errorCode; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/MemberErrorCode.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum MemberErrorCode implements ErrorCode { | ||
EMPTY_MEMBER("MEMBER_001", "존재하지 않는 사용자입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/PostErrorCode.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum PostErrorCode implements ErrorCode { | ||
EMPTY_POST("POST_001", "존재하지 않는 게시글입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/RecordErrorCode.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum RecordErrorCode implements ErrorCode { | ||
EMPTY_RECORD("RECORD_001", "존재하지 않는 기록입니다."), | ||
; | ||
private final String errorCode; | ||
private final String message; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/todaysgym/todaysgym/config/exception/errorCode/ReportErrorCode.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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.todaysgym.todaysgym.config.exception.errorCode; | ||
|
||
import com.todaysgym.todaysgym.config.exception.ErrorCode; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ReportErrorCode implements ErrorCode { | ||
REPORT_USER_DUPLICATE("REPORT_001", "이미 신고한 유저입니다."); | ||
|
||
private final String errorCode; | ||
private final String message; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/todaysgym/todaysgym/config/response/BaseResponse.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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.todaysgym.todaysgym.config.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class BaseResponse<T> { | ||
|
||
private final String code; | ||
private final String message; | ||
private T result; | ||
|
||
public BaseResponse(T result) { | ||
this.code = "SUCCESS"; | ||
this.message = "요청에 성공했습니다."; | ||
this.result = result; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/todaysgym/todaysgym/config/response/ExceptionResponse.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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.todaysgym.todaysgym.config.response; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ExceptionResponse { | ||
|
||
private final String code; | ||
private final String message; | ||
|
||
public ExceptionResponse(String code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/todaysgym/todaysgym/member/MemberRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.todaysgym.todaysgym.member; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
Optional<Member> getByMemberId(Long memberId); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/todaysgym/todaysgym/post/PostRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.todaysgym.todaysgym.post; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
Optional<Post> getByPostId(Long postId); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/todaysgym/todaysgym/post/comment/CommentRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.todaysgym.todaysgym.post.comment; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
Optional<Comment> getByCommentId(Long commentId); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/todaysgym/todaysgym/post/like/PostLikeRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.todaysgym.todaysgym.post.like; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostLikeRepository extends JpaRepository<PostLike, Long> { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/todaysgym/todaysgym/post/photo/PostPhotoRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.todaysgym.todaysgym.post.photo; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostPhotoRepository extends JpaRepository<PostPhoto, Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/todaysgym/todaysgym/record/RecordRepository.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.todaysgym.todaysgym.record; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RecordRepository extends JpaRepository<Record, Long> { | ||
Optional<Record> getByRecordId(Long recordId); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/todaysgym/todaysgym/record/photo/RecordPhotoRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.todaysgym.todaysgym.record.photo; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface RecordPhotoRepository extends JpaRepository<RecordPhoto, Long> { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/todaysgym/todaysgym/report/ReportController.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.todaysgym.todaysgym.report; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/todaysgym/todaysgym/report/ReportRepository.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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.todaysgym.todaysgym.report; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> { | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/todaysgym/todaysgym/report/ReportService.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.todaysgym.todaysgym.report; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ReportService { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.todaysgym.todaysgym.tag; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TagRepository extends JpaRepository<Tag, Long> { | ||
|
||
} |
Oops, something went wrong.