using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using SimApi.Helpers;
namespace SimApi.Communications;
///
/// 基础相应
///
public class SimApiBaseResponse(int code = 200, string message = "成功")
{
public int Code { get; set; } = code;
public string Message { get; set; } = message;
public SimApiBaseResponse() : this(200, "成功")
{
}
///
/// 默认错误代码对应提示信息
///
private static readonly Dictionary MsgBox = new()
{
{ 200, "成功" },
{ 204, "没有数据" },
{ 400, "参数错误" },
{ 401, "需要登录" },
{ 403, "无权访问" },
{ 404, "接口不存在" },
{ 500, "服务器错误" }
};
public SimApiBaseResponse(int code) : this(code, MsgBox.GetValueOrDefault(code, "未知错误"))
{
}
///
/// 序列化为JSON字符串
///
///
public override string ToString()
{
return SimApiUtil.Json(this);
}
}
///
/// 动态内容分页
///
///
public class SimApiBasePageResponse() : SimApiBaseResponse
{
public T? List { get; set; }
public int Page { get; set; } = 1;
public int Count { get; set; } = 20;
public int Total { get; set; }
public SimApiBasePageResponse(T list, int page, int count, int total) : this()
{
List = list;
Page = page;
Count = count;
Total = total;
}
}
///
/// 动态Data返回
///
///
public class SimApiBaseResponse() : SimApiBaseResponse
{
public T? Data { get; set; }
public SimApiBaseResponse(T data) : this()
{
Data = data;
}
}