|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using Newtonsoft.Json.Serialization;
- using Newtonsoft.Json;
-
- namespace HealthMonitor.WebApi.Controllers.Api
- {
- public class ApiResponse<T>
- {
- public string Timestamp { get; set; } = default!;
-
- public T Data { get; set; } = default!;
-
- public Result Result { get; set; } = default!;
-
- //public bool Succeeded { get; set; }
- // public string Message { get; set; } = String.Empty;
-
-
- public static ApiResponse<T> Fail(int code, string errorMessage) => new()
- {
- //MsgType = msgType,
- //Signature = signature,
- Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
- Result = new()
- {
- Status = "failed",
- Code = code,
- Message = errorMessage,
- },
-
- };
-
- //public static ApiResponse<T> Success(string msgType,string signature,T data) => new()
- //{
- // MsgType= msgType,
- // Signature = signature,
- // Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
- // Data = data,
- // Result = new()
- // {
- // Status = "succeed",
- // Code = 200,
- // Message = "请求成功!",
- // },
- //};
- public static ApiResponse<T> Success(T data) => new()
- {
- Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),
- Data = data,
- Result = new()
- {
- Status = "succeed",
- Code = 200,
- Message = "请求成功!",
- },
- };
- public string ToJsonString()
- {
- var settings = new JsonSerializerSettings
- {
- DateFormatString = "yyyy-MM-dd HH:mm:ss.fff", // 设置日期格式
- ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }
- };
- return JsonConvert.SerializeObject(this, settings);
- }
- }
-
-
- public class Result
- {
- public string Status { get; set; } = default!;
- public int Code { get; set; }
- public string Message { get; set; } = default!;
- }
- }
|