22 lines
653 B
Java
22 lines
653 B
Java
package com.yaoyuan.jiscuss.response;
|
|
|
|
/**
|
|
* Unified API response wrapper.
|
|
*
|
|
* @param <T> payload type
|
|
*/
|
|
public record ApiResponse<T>(int code, String msg, T data) {
|
|
|
|
public static <T> ApiResponse<T> ok(T data) {
|
|
return new ApiResponse<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMsg(), data);
|
|
}
|
|
|
|
public static <T> ApiResponse<T> fail(ResponseCode responseCode) {
|
|
return new ApiResponse<>(responseCode.getCode(), responseCode.getMsg(), null);
|
|
}
|
|
|
|
public static <T> ApiResponse<T> error(String message) {
|
|
return new ApiResponse<>(ResponseCode.SERVICE_ERROR.getCode(), message, null);
|
|
}
|
|
}
|