From 4a889e33f5f26b68862fe99e01743c780505d453 Mon Sep 17 00:00:00 2001 From: CHAE Date: Sun, 15 Oct 2023 20:41:44 +0900 Subject: [PATCH] =?UTF-8?q?:recycle:=20Refactor:=20Api=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20=EA=B0=9D=EC=B2=B4=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/diareat/diareat/util/api/ApiBody.java | 16 ---------------- .../com/diareat/diareat/util/api/ApiHeader.java | 13 +++++-------- .../diareat/diareat/util/api/ApiResponse.java | 16 +++++++--------- 3 files changed, 12 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/com/diareat/diareat/util/api/ApiBody.java diff --git a/src/main/java/com/diareat/diareat/util/api/ApiBody.java b/src/main/java/com/diareat/diareat/util/api/ApiBody.java deleted file mode 100644 index d4fca17..0000000 --- a/src/main/java/com/diareat/diareat/util/api/ApiBody.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.diareat.diareat.util.api; - -public class ApiBody { - - private final T data; - private final T msg; - - public ApiBody(T data, T msg) { - this.data = data; - this.msg = msg; - } - - public T getData() { - return data; - } -} diff --git a/src/main/java/com/diareat/diareat/util/api/ApiHeader.java b/src/main/java/com/diareat/diareat/util/api/ApiHeader.java index f6c4fb9..7788e9a 100644 --- a/src/main/java/com/diareat/diareat/util/api/ApiHeader.java +++ b/src/main/java/com/diareat/diareat/util/api/ApiHeader.java @@ -1,18 +1,15 @@ package com.diareat.diareat.util.api; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor public class ApiHeader { private int code; private String message; - public ApiHeader(int code, String message) { - this.code = code; - this.message = message; - } - - public ApiHeader() { - } - public int getCode() { return code; } diff --git a/src/main/java/com/diareat/diareat/util/api/ApiResponse.java b/src/main/java/com/diareat/diareat/util/api/ApiResponse.java index 4fe2374..ba96c5e 100644 --- a/src/main/java/com/diareat/diareat/util/api/ApiResponse.java +++ b/src/main/java/com/diareat/diareat/util/api/ApiResponse.java @@ -8,24 +8,22 @@ public class ApiResponse { private ApiHeader header; - private ApiBody body; + private T data; + private String msg; private static final int SUCCESS = 200; - public ApiResponse(ApiHeader header, ApiBody body) { - this.header = header; - this.body = body; - } - - public ApiResponse(ApiHeader header) { + private ApiResponse(ApiHeader header, T data, String msg) { this.header = header; + this.data = data; + this.msg = msg; } public static ApiResponse success(T data, String message) { - return new ApiResponse(new ApiHeader(SUCCESS, "SUCCESS"), new ApiBody(data, message)); + return new ApiResponse(new ApiHeader(SUCCESS, "SUCCESS"), data, message); } public static ApiResponse fail(ResponseCode responseCode) { - return new ApiResponse(new ApiHeader(responseCode.getHttpStatusCode(), responseCode.getMessage()), new ApiBody(null, responseCode.getMessage())); + return new ApiResponse(new ApiHeader(responseCode.getHttpStatusCode(), responseCode.getMessage()), null, responseCode.getMessage()); } } \ No newline at end of file