|
|
@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
|
|
[Produces("application/json")]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
|
|
public class DefaultControllerBase : ControllerBase
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData<T> Succeed<T>(T data, string message = "successful")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new MessageData<T>(data, true, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData Succeed(string message = "successful", int code = 200)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new MessageData(true, message, code);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData Fail(string message = "failed", int code = 500)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new MessageData(false, message, code);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData<T?> Fail<T>(string message = "failed", int code = 500)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new MessageData<T?>(default, false, message, code);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData<PageData<T>> SucceedPage<T>(int page, int dataCount, int pageSize, List<T> data,
|
|
|
|
|
|
|
|
int pageCount,
|
|
|
|
|
|
|
|
string message = "successful")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var pageData = new PageData<T>()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Data = data,
|
|
|
|
|
|
|
|
TotalPages = pageCount,
|
|
|
|
|
|
|
|
PageSize = pageSize,
|
|
|
|
|
|
|
|
Page = page,
|
|
|
|
|
|
|
|
TotalItems = dataCount,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return new MessageData<PageData<T>>(pageData, true, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[NonAction]
|
|
|
|
|
|
|
|
[ApiExplorerSettings(IgnoreApi = true)]
|
|
|
|
|
|
|
|
public static MessageData<PageData<T>> SucceedPage<T>(PageData<T> page, string message = "successful")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new MessageData<PageData<T>>(page, true, message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|