2024-01-02 10:16:15 +08:00
|
|
|
package com.realtime.protection.configuration.response;
|
|
|
|
|
|
2024-01-12 14:31:34 +08:00
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
2024-01-02 10:16:15 +08:00
|
|
|
import lombok.Data;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
2024-01-05 21:42:19 +08:00
|
|
|
import java.util.Map;
|
2024-01-02 10:16:15 +08:00
|
|
|
|
|
|
|
|
@Data
|
2024-01-12 19:24:19 +08:00
|
|
|
@Schema(description = "用于所有接口返回的通用返回对象")
|
2024-01-02 10:16:15 +08:00
|
|
|
public class ResponseResult implements Serializable {
|
|
|
|
|
|
2024-01-12 14:31:34 +08:00
|
|
|
@Schema(description = "状态码")
|
2024-01-02 10:16:15 +08:00
|
|
|
private int code;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
|
|
|
|
@Schema(description = "返回信息")
|
2024-01-02 10:16:15 +08:00
|
|
|
private String message;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
|
|
|
|
@Schema(description = "封装数据")
|
2024-01-19 15:09:23 +08:00
|
|
|
private ResponseData data;
|
2024-01-12 14:31:34 +08:00
|
|
|
|
|
|
|
|
@Schema(description = "返回对象链接的另外一个返回对象")
|
2024-01-11 19:49:07 +08:00
|
|
|
private ResponseResult another;
|
2024-01-02 10:16:15 +08:00
|
|
|
|
2024-01-19 15:09:23 +08:00
|
|
|
public ResponseResult(int code, String message, ResponseData data) {
|
2024-01-02 10:16:15 +08:00
|
|
|
this.code = code;
|
|
|
|
|
this.message = message;
|
|
|
|
|
this.data = data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseResult(int code) {
|
|
|
|
|
this.code = code;
|
2024-01-19 15:09:23 +08:00
|
|
|
this.data = new ResponseData();
|
2024-01-02 10:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseResult(int code, String message) {
|
|
|
|
|
this.code = code;
|
|
|
|
|
this.message = message;
|
2024-01-19 15:09:23 +08:00
|
|
|
this.data = new ResponseData();
|
2024-01-02 10:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ResponseResult ok() {
|
2024-01-03 22:53:02 +08:00
|
|
|
return new ResponseResult(200, "request succeed");
|
2024-01-02 10:16:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ResponseResult ok(String message) {
|
|
|
|
|
return new ResponseResult(200, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ResponseResult error() {
|
|
|
|
|
return new ResponseResult(500, "request failed");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:53:02 +08:00
|
|
|
public static ResponseResult invalid() {
|
|
|
|
|
return new ResponseResult(400, "invalid request");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-05 21:42:19 +08:00
|
|
|
public static ResponseResult invalid(String message) {
|
|
|
|
|
return new ResponseResult(400, message);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-03 22:53:02 +08:00
|
|
|
public static ResponseResult unAuthorized() {
|
|
|
|
|
return new ResponseResult(401, "UnAuthorized User");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-02 10:16:15 +08:00
|
|
|
public static ResponseResult error(String message) {
|
|
|
|
|
return new ResponseResult(500, message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseResult setCode(int code) {
|
|
|
|
|
this.code = code;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseResult setMessage(String message) {
|
|
|
|
|
this.message = message;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResponseResult setData(String key, Object value) {
|
|
|
|
|
this.data.put(key, value);
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 15:09:23 +08:00
|
|
|
public ResponseResult addDataMap(Map<String, Object> data) {
|
|
|
|
|
this.data = (ResponseData) data;
|
2024-01-02 10:16:15 +08:00
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|