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