64 lines
1.7 KiB
Java
64 lines
1.7 KiB
Java
package com.myoa.engineering.crawl.ppomppu.support.dto;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.Map;
|
|
import lombok.Getter;
|
|
|
|
/**
|
|
* APIResponse
|
|
*
|
|
* @author Shin Woo-jin (woozu.shin@kakaoent.com)
|
|
* @since 2021-09-07
|
|
*/
|
|
@Getter
|
|
public class APIResponse<T> implements Serializable {
|
|
private static final long serialVersionUID = 1523350013713908487L;
|
|
|
|
private boolean success;
|
|
private T result;
|
|
private APIResponseError error;
|
|
|
|
public APIResponse(boolean success, T result, APIResponseError error) {
|
|
this.success = success;
|
|
this.error = error;
|
|
this.result = result;
|
|
}
|
|
|
|
public APIResponse(boolean success, T result) {
|
|
this.success = success;
|
|
this.result = result;
|
|
}
|
|
|
|
public APIResponse(boolean success, APIResponseError error) {
|
|
this.success = success;
|
|
this.error = error;
|
|
}
|
|
|
|
public APIResponse() {}
|
|
|
|
public static <T> APIResponse<T> success(T result) {
|
|
return new APIResponse<>(true, result);
|
|
}
|
|
|
|
public static APIResponse<Void> success() {
|
|
return new APIResponse<>(true, null);
|
|
}
|
|
|
|
public static <T> APIResponse<T> fail(T result, String code) {
|
|
return new APIResponse<T>(false, result, APIResponseError.of(code));
|
|
}
|
|
|
|
public static APIResponse<Void> fail(String code) {
|
|
return new APIResponse<Void>(false, APIResponseError.of(code));
|
|
}
|
|
|
|
public static APIResponse<Void> fail(String code, String message) {
|
|
return new APIResponse<Void>(false, APIResponseError.of(code, message));
|
|
}
|
|
|
|
public static <K, V> APIResponse<Void> fail(String code, String message, Map<K, V> reasons) {
|
|
return new APIResponse<Void>(false, APIResponseError.of(code, message, reasons));
|
|
}
|
|
|
|
}
|