123 lines
3.1 KiB
C#
123 lines
3.1 KiB
C#
using System.Text.Json;
|
|
|
|
namespace AcaMate.Common.Models;
|
|
|
|
public class APIResponseStatus<T>
|
|
{
|
|
public Status status { get; set; }
|
|
public T? data { get; set; }
|
|
|
|
public string JsonToString()
|
|
{
|
|
return JsonSerializer.Serialize(this);
|
|
}
|
|
}
|
|
|
|
public class Status
|
|
{
|
|
public string code { get; set; }
|
|
public string message { get; set; }
|
|
|
|
}
|
|
|
|
public static class APIResponse
|
|
{
|
|
public static APIResponseStatus<T> Send<T>(string code, string message, T data)
|
|
{
|
|
return new APIResponseStatus<T>
|
|
{
|
|
status = new Status()
|
|
{
|
|
code = code,
|
|
message = message
|
|
},
|
|
data = data
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 반환값 없는 API 정상 동작시
|
|
/// </summary>
|
|
public static APIResponseStatus<string> Success (){
|
|
return Send("000", "정상", "");
|
|
}
|
|
|
|
public static APIResponseStatus<string> InvalidInputError()
|
|
{
|
|
return Send("100", "입력 값이 유효하지 않습니다.", "");
|
|
}
|
|
|
|
public static APIResponseStatus<string> NotFoundError()
|
|
{
|
|
return Send("200", "알맞은 값을 찾을 수 없습니다.", "");
|
|
}
|
|
|
|
public static APIResponseStatus<string> InternalSeverError()
|
|
{
|
|
return Send("300", "통신에 오류가 발생하였습니다.", "");
|
|
}
|
|
|
|
public static APIResponseStatus<string> UnknownError()
|
|
{
|
|
return Send("999", "알 수 없는 오류가 발생하였습니다.", "");
|
|
}
|
|
}
|
|
//
|
|
// public static class DefaultResponse
|
|
// {
|
|
// // private static readonly Lazy<ErrorResponse> _instance = new Lazy<ErrorResponse>();
|
|
// // public static ErrorResponse Instace => _instance.Value;
|
|
//
|
|
// // private ErrorResponse()
|
|
// // {
|
|
// // // 외부 초기화 방지
|
|
// // }
|
|
//
|
|
//
|
|
// public static APIResponseStatus<string> Success = new APIResponseStatus<string>
|
|
// {
|
|
// status = new Status()
|
|
// {
|
|
// code = "000",
|
|
// message = "정상"
|
|
// }
|
|
// };
|
|
//
|
|
// public static APIResponseStatus<string> InvalidInputError = new APIResponseStatus<string>
|
|
// {
|
|
// status = new Status()
|
|
// {
|
|
// code = "001",
|
|
// message = "입력 값이 유효하지 않습니다."
|
|
// }
|
|
// };
|
|
//
|
|
// public static APIResponseStatus<string> NotFoundError = new APIResponseStatus<string>
|
|
// {
|
|
// status = new Status()
|
|
// {
|
|
// code = "002",
|
|
// message = "알맞은 값을 찾을 수 없습니다."
|
|
// }
|
|
// };
|
|
//
|
|
// public static APIResponseStatus<string> InternalSeverError = new APIResponseStatus<string>
|
|
// {
|
|
// status = new Status
|
|
// {
|
|
// code = "003",
|
|
// message = "통신에 오류가 발생하였습니다."
|
|
// }
|
|
// };
|
|
//
|
|
//
|
|
// public static APIResponseStatus<string> UnknownError = new APIResponseStatus<string>
|
|
// {
|
|
// status = new Status()
|
|
// {
|
|
// code = "999",
|
|
// message = "알 수 없는 오류가 발생하였습니다."
|
|
// }
|
|
// };
|
|
// }
|