feat: ApiResponse<T> 공통 응답 포맷 구현 (#14)
Some checks failed
SPMS_API/pipeline/head There was a failure building this commit
Some checks failed
SPMS_API/pipeline/head There was a failure building this commit
Reviewed-on: https://git.ipstein.myds.me/SPMS/SPMS_API/pulls/15
This commit is contained in:
commit
f380b348a9
33
SPMS.Domain/Common/ApiResponse.cs
Normal file
33
SPMS.Domain/Common/ApiResponse.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace SPMS.Domain.Common;
|
||||||
|
|
||||||
|
public class ApiResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("result")]
|
||||||
|
public bool Result { get; init; }
|
||||||
|
|
||||||
|
[JsonPropertyName("code")]
|
||||||
|
public string Code { get; init; } = ErrorCodes.Success;
|
||||||
|
|
||||||
|
[JsonPropertyName("msg")]
|
||||||
|
public string Msg { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
public static ApiResponse Success()
|
||||||
|
=> new() { Result = true, Code = ErrorCodes.Success };
|
||||||
|
|
||||||
|
public static ApiResponse Fail(string code, string msg)
|
||||||
|
=> new() { Result = false, Code = code, Msg = msg };
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApiResponse<T> : ApiResponse
|
||||||
|
{
|
||||||
|
[JsonPropertyName("data")]
|
||||||
|
public T? Data { get; init; }
|
||||||
|
|
||||||
|
public static ApiResponse<T> Success(T data)
|
||||||
|
=> new() { Result = true, Code = ErrorCodes.Success, Data = data };
|
||||||
|
|
||||||
|
public new static ApiResponse<T> Fail(string code, string msg)
|
||||||
|
=> new() { Result = false, Code = code, Msg = msg };
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user