Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ out/
/.nb-gradle/

### VS Code ###
.vscode/
.vscode/

### env ###
.env
Empty file.
21 changes: 21 additions & 0 deletions src/main/java/com/ftm/server/common/exception/CustomException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ftm.server.common.exception;

import com.ftm.server.common.response.enums.ErrorResponseCode;
import lombok.Getter;

@Getter
public class CustomException extends RuntimeException {

private final ErrorResponseCode errorResponseCode;

public CustomException(ErrorResponseCode errorResponseCode) {
super(errorResponseCode.getMessage()); // 예외 메시지 설정
this.errorResponseCode = errorResponseCode;
}

public static CustomException USER_NOT_FOUND =
new CustomException(ErrorResponseCode.USER_NOT_FOUND);

public static CustomException USER_ALREADY_EXISTS =
new CustomException(ErrorResponseCode.USER_ALREADY_EXISTS);
}
Empty file.
40 changes: 40 additions & 0 deletions src/main/java/com/ftm/server/common/response/ApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.ftm.server.common.response;

import com.ftm.server.common.response.enums.ErrorResponseCode;
import com.ftm.server.common.response.enums.SuccessResponseCode;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class ApiResponse<T> {

private final Integer status;
private final String code;
private final String message;
private final T data;

public static <T> ApiResponse<T> success(SuccessResponseCode responseCode) {
return success(responseCode, null);
}

public static <T> ApiResponse<T> success(SuccessResponseCode responseCode, T data) {
return new ApiResponse<>(
responseCode.getHttpStatus().value(),
responseCode.getCode(),
responseCode.getMessage(),
data);
}

public static <T> ApiResponse<T> fail(ErrorResponseCode responseCode) {
return fail(responseCode, null);
}

public static <T> ApiResponse<T> fail(ErrorResponseCode responseCode, T data) {
return new ApiResponse<>(
responseCode.getHttpStatus().value(),
responseCode.getCode(),
responseCode.getMessage(),
data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ftm.server.common.response.enums;

import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum ErrorResponseCode {

// 400번
INVALID_REQUEST_ARGUMENT(
HttpStatus.BAD_REQUEST, "E400_001", "클라이언트 요청이 잘못된 형식이거나, 필수 데이터가 누락되었습니다."),

// 401번
NOT_AUTHENTICATED(HttpStatus.UNAUTHORIZED, "E401_001", "인증되지 않은 사용자입니다."),

// 403번
NOT_AUTHORIZATION(HttpStatus.FORBIDDEN, "E403_001", "인증된 사용자이나 해당 자원에 대한 접근 권한이 없습니다."),

// 404번
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "E404_001", "요청된 사용자를 찾을 수 없습니다."),

// 409번
USER_ALREADY_EXISTS(HttpStatus.CONFLICT, "E409_001", "이미 존재하는 사용자입니다."),
PASSWORD_NOT_MATCHED(HttpStatus.CONFLICT, "E409_002", "비밀번호가 일치하지 않습니다."),

// 500번
UNKNOWN_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "E500_001", "알 수 없는 서버 에러가 발생했습니다.");

private final HttpStatus httpStatus;
private final String code;
private final String message;

ErrorResponseCode(HttpStatus httpStatus, String code, String message) {
this.httpStatus = httpStatus;
this.code = code;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.ftm.server.common.response.enums;

import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
public enum SuccessResponseCode {
OK(HttpStatus.OK, "S001", "클라이언트 요청이 정상적으로 처리됨."),
CREATED(HttpStatus.CREATED, "S002", "새로운 리소스가 성공적으로 생성됨."),
ACCEPTED(HttpStatus.ACCEPTED, "S003", "요청은 수락되었지만 아직 처리가 완료되지 않음."),
NO_CONTENT(HttpStatus.NO_CONTENT, "S004", "요청이 성공적으로 처리되었지만, 응답 본문이 필요 없음.");

private final HttpStatus httpStatus;
private final String code;
private final String message;

SuccessResponseCode(HttpStatus httpStatus, String code, String message) {
this.httpStatus = httpStatus;
this.code = code;
this.message = message;
}
}
1 change: 1 addition & 0 deletions src/main/resources/application-datasource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ spring:
password: ${POSTGRES_PASSWORD}

jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
properties:
hibernate:
default_batch_fetch_size: ${JPA_BATCH_FETCH_SIZE:100}