Skip to content

Commit

Permalink
Merge branch 'develop' into #14/record
Browse files Browse the repository at this point in the history
  • Loading branch information
SeWooooong committed Mar 21, 2023
2 parents 67fc83a + d684f5e commit c317e29
Show file tree
Hide file tree
Showing 25 changed files with 444 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/main/java/com/todaysgym/todaysgym/config/ControllerAdvice.java
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;
}
}
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();
}
}
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();
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
}
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;
}
}
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);
}
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);

}
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);

}
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> {

}
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> {

}
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);

}
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 src/main/java/com/todaysgym/todaysgym/report/ReportController.java
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 {

}
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 src/main/java/com/todaysgym/todaysgym/report/ReportService.java
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 {

}
7 changes: 7 additions & 0 deletions src/main/java/com/todaysgym/todaysgym/tag/TagRepository.java
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> {

}
Loading

0 comments on commit c317e29

Please sign in to comment.