From 91025c8fcaac1bd6d13cc8cefe80d45ace799698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=8B=E1=85=B5=E1=84=89?= =?UTF-8?q?=E1=85=A1=E1=86=A8?= Date: Fri, 7 May 2021 01:43:53 +0900 Subject: [PATCH] [#6] feat: Create common response DTO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit response에 사용될 공통 형식인 ApiResult 클래스 생성 --- .../baseball/DTO/response/ApiResult.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 BE/baseball/src/main/java/team9/baseball/DTO/response/ApiResult.java diff --git a/BE/baseball/src/main/java/team9/baseball/DTO/response/ApiResult.java b/BE/baseball/src/main/java/team9/baseball/DTO/response/ApiResult.java new file mode 100644 index 000000000..33d221630 --- /dev/null +++ b/BE/baseball/src/main/java/team9/baseball/DTO/response/ApiResult.java @@ -0,0 +1,36 @@ +package team9.baseball.DTO.response; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ApiResult { + private T data; + private String error; + + private ApiResult(T data, String error) { + this.data = data; + this.error = error; + } + + public static ApiResult succeed(T data) { + return new ApiResult(data, null); + } + + public static ApiResult failed(String errorMessage) { + return new ApiResult<>(null, errorMessage); + } + + public static ApiResult failed(Throwable throwable) { + return failed(throwable.getMessage()); + } + + public T getData() { + return data; + } + + public String getError() { + return error; + } +}