update
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user