74 lines
2.1 KiB
C#
74 lines
2.1 KiB
C#
using System.Text.Json;
|
|
|
|
namespace Back.Program.Common.Model
|
|
{
|
|
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<object> Success (){
|
|
return Send<object>("000", "정상", new {});
|
|
}
|
|
|
|
public static APIResponseStatus<object> InvalidInputError(string? msg = null)
|
|
{
|
|
return Send<object>("100", msg ?? "입력 값이 유효하지 않습니다.", new {});
|
|
}
|
|
|
|
public static APIResponseStatus<object> AccessExpireError(string? msg = null)
|
|
{
|
|
return Send<object>("101", msg ?? "엑세스 토큰이 유효하지 않습니다.", new {});
|
|
}
|
|
|
|
|
|
// -- -- -- OUTPUT ERROR -- -- -- //
|
|
public static APIResponseStatus<object> NotFoundError(string? msg = null)
|
|
{
|
|
return Send<object>("200", msg ?? "알맞은 값을 찾을 수 없습니다.", new {});
|
|
}
|
|
|
|
|
|
|
|
public static APIResponseStatus<object> InternalSeverError(string? msg = null)
|
|
{
|
|
return Send<object>("300", msg ?? "통신에 오류가 발생하였습니다.", new {});
|
|
}
|
|
|
|
public static APIResponseStatus<object> UnknownError(string? msg = null)
|
|
{
|
|
return Send<object>("999", msg ?? "알 수 없는 오류가 발생하였습니다.", new {});
|
|
}
|
|
}
|
|
} |