-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor] : ApiResponse 구현 및 meetings 적용
- Loading branch information
1 parent
79730f7
commit 472a12d
Showing
6 changed files
with
111 additions
and
54 deletions.
There are no files selected for viewing
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/example/bigbrotherbe/global/exception/enums/SuccessCode.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.example.bigbrotherbe.global.exception.enums; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum SuccessCode { | ||
// SUCCESS | ||
SUCCESS(HttpStatus.OK, "SUCCESS", "요청에 성공하였습니다."); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String successCode; | ||
private final String message; | ||
} |
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
59 changes: 59 additions & 0 deletions
59
src/main/java/com/example/bigbrotherbe/global/exception/response/ApiResponse.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,59 @@ | ||
package com.example.bigbrotherbe.global.exception.response; | ||
|
||
import com.example.bigbrotherbe.global.exception.enums.ErrorCode; | ||
import com.example.bigbrotherbe.global.exception.enums.SuccessCode; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.*; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class ApiResponse<T> { | ||
private HttpStatus status; | ||
private int httpStatusCode; | ||
private String responseCode; | ||
private String resultMsg; | ||
private T data; | ||
|
||
// @Builder | ||
// protected ApiResponse(final ErrorCode code) { | ||
// this.status = code.getHttpStatus(); | ||
// this.responseCode = code.getErrorCode(); | ||
// this.resultMsg = code.getMessage(); | ||
// } | ||
|
||
public static <T> ApiResponse<T> success(final SuccessCode successCode) { | ||
return ApiResponse.<T>builder() | ||
.status(successCode.getHttpStatus()) | ||
.httpStatusCode(successCode.getHttpStatus().value()) | ||
.responseCode(successCode.getSuccessCode()) | ||
.resultMsg(successCode.getMessage()) | ||
.build(); | ||
} | ||
|
||
public static <T> ApiResponse<T> success(final SuccessCode successCode, final T data) { | ||
return ApiResponse.<T>builder() | ||
.status(successCode.getHttpStatus()) | ||
.httpStatusCode(successCode.getHttpStatus().value()) | ||
.responseCode(successCode.getSuccessCode()) | ||
.resultMsg(successCode.getMessage()) | ||
.data(data) | ||
.build(); | ||
} | ||
|
||
public static ApiResponse<?> error(final ErrorCode errorCode) { | ||
return ApiResponse.builder() | ||
.status(errorCode.getHttpStatus()) | ||
.httpStatusCode(errorCode.getHttpStatus().value()) | ||
.responseCode(errorCode.getErrorCode()) | ||
.resultMsg(errorCode.getMessage()) | ||
.build(); | ||
} | ||
|
||
// public static ApiResponse of(final ErrorCode code) { | ||
// return new ApiResponse(code); | ||
// } | ||
} |
27 changes: 0 additions & 27 deletions
27
src/main/java/com/example/bigbrotherbe/global/exception/response/ExceptionResponse.java
This file was deleted.
Oops, something went wrong.