From 6493b3223c80624a323233b8ef288eeec0992df3 Mon Sep 17 00:00:00 2001 From: gdakate Date: Tue, 21 Mar 2023 14:52:58 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20=ED=97=A4=EB=8D=94=20response=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HighLight/common/ApiBody.java | 18 +++++++++ .../HighLight/common/ApiHeader.java | 21 ++++++++++ .../HighLight/common/ApiResponse.java | 39 ++++++++++++++----- .../HighLight/common/Success.java | 14 +++++++ 4 files changed, 82 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/SollutionChallenge/HighLight/common/ApiBody.java create mode 100644 src/main/java/com/SollutionChallenge/HighLight/common/ApiHeader.java diff --git a/src/main/java/com/SollutionChallenge/HighLight/common/ApiBody.java b/src/main/java/com/SollutionChallenge/HighLight/common/ApiBody.java new file mode 100644 index 0000000..84f261e --- /dev/null +++ b/src/main/java/com/SollutionChallenge/HighLight/common/ApiBody.java @@ -0,0 +1,18 @@ +package com.SollutionChallenge.HighLight.common; + +public class ApiBody { + private T data; + private T msg; + + public ApiBody(T data, T msg){ + this.data = data; + this.msg = msg; + } + + public T getData(){ + return data; + } + public T getMsg(){ + return msg; + } +} diff --git a/src/main/java/com/SollutionChallenge/HighLight/common/ApiHeader.java b/src/main/java/com/SollutionChallenge/HighLight/common/ApiHeader.java new file mode 100644 index 0000000..2de1080 --- /dev/null +++ b/src/main/java/com/SollutionChallenge/HighLight/common/ApiHeader.java @@ -0,0 +1,21 @@ +package com.SollutionChallenge.HighLight.common; + +import org.springframework.http.HttpStatus; + +public class ApiHeader { + private HttpStatus status; + private String message; + + public ApiHeader(HttpStatus status, String message) { + this.status = status; + this.message = message; + } + + public HttpStatus getStatus() { + return status; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/com/SollutionChallenge/HighLight/common/ApiResponse.java b/src/main/java/com/SollutionChallenge/HighLight/common/ApiResponse.java index 837f6a5..2f8e24b 100644 --- a/src/main/java/com/SollutionChallenge/HighLight/common/ApiResponse.java +++ b/src/main/java/com/SollutionChallenge/HighLight/common/ApiResponse.java @@ -1,5 +1,7 @@ package com.SollutionChallenge.HighLight.common; +import com.SollutionChallenge.HighLight.Folder.FolderResponseDto; + import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -7,18 +9,35 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class ApiResponse { - private int status; - private T data; - private String message; - - private ApiResponse(int status, String message, T data) { - this.status = status; - this.data = data; - this.message = message; + private ApiHeader header; + private ApiBody body; + private static int SUCCESS =200; + + // private int status; + // private T data; + // private String message; + + // private ApiResponse(int status, String message, T data) { + // this.status = status; + // this.data = data; + // this.message = message; + // } + + private ApiResponse(ApiHeader header, ApiBody body){ + this.header = header; + this.body=body; } - public static ApiResponse successCode(Success success, T data){ - return new ApiResponse<>(success.getStatus().value(), success.getMessage(),null); + public ApiResponse(ApiHeader header){ + this.header = header; + } + + // public static ApiResponse successCode(Success success, T data){ + // return new ApiResponse<>(success.getStatus().value(), success.getMessage(),null); + // } + + public static ApiResponse successCode(Success success, FolderResponseDto response){ + return new ApiResponse(new ApiHeader(success.getStatus(), success.getMessage()), new ApiBody(null, success.getMessage())); } } diff --git a/src/main/java/com/SollutionChallenge/HighLight/common/Success.java b/src/main/java/com/SollutionChallenge/HighLight/common/Success.java index 07091ae..064c1b7 100644 --- a/src/main/java/com/SollutionChallenge/HighLight/common/Success.java +++ b/src/main/java/com/SollutionChallenge/HighLight/common/Success.java @@ -4,6 +4,8 @@ import org.springframework.http.HttpStatus; +import com.google.api.Http; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -17,4 +19,16 @@ public enum Success { private final HttpStatus status; private final String message; + + // Success(HttpStatus status, String message){ + // this.status = status; + // this.message=message; + // } + // public HttpStatus getStatus(){ + // return status; + // } + // + // public String getMessage(){ + // return message; + // } }