Skip to content

Commit

Permalink
[#6] feat: Create common response DTO
Browse files Browse the repository at this point in the history
response에 사용될 공통 형식인 ApiResult 클래스 생성
  • Loading branch information
isaac56 committed May 6, 2021
1 parent 7cbb434 commit 91025c8
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package team9.baseball.DTO.response;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ApiResult<T> {
private T data;
private String error;

private ApiResult(T data, String error) {
this.data = data;
this.error = error;
}

public static <T> ApiResult<T> 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;
}
}

0 comments on commit 91025c8

Please sign in to comment.