105040 增加封装函数,直接构造返回结果
This commit is contained in:
parent
548cc42d60
commit
4084e01c31
|
|
@ -1,3 +1,4 @@
|
|||
using LFlow.Base.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LFlow.Base.Interfaces;
|
||||
|
|
@ -10,5 +11,21 @@ namespace LFlow.Base.Interfaces;
|
|||
[ApiController]
|
||||
public abstract class BaseController : ControllerBase, IController
|
||||
{
|
||||
protected virtual ApiResult<T> Success<T>(T data) where T : class, new()
|
||||
{
|
||||
return ApiResult<T>.SuccessResult(data);
|
||||
}
|
||||
protected virtual PagedApiResult<T> Success<T>(T data, int totalCount, int pageIndex, int pageSize) where T : class, new()
|
||||
{
|
||||
return PagedApiResult<T>.SuccessResult(data, totalCount, pageIndex, pageSize);
|
||||
}
|
||||
|
||||
protected virtual ApiResult<T> Fail<T>(T data, string errorMsg, int errCode) where T : class, new()
|
||||
{
|
||||
return ApiResult<T>.FailResult(errorMsg, errCode);
|
||||
}
|
||||
protected virtual PagedApiResult<T> PagedFail<T>(T? data, string errorMsg, int errCode) where T : class, new()
|
||||
{
|
||||
return PagedApiResult<T>.FailResult(errorMsg, errCode);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Reflection;
|
||||
using LFlow.Base.Interfaces;
|
||||
using LFlow.Base.Interfaces;
|
||||
using LFlow.Base.Utils;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using SqlSugar;
|
||||
using System.Reflection;
|
||||
|
||||
namespace LFlow.Base;
|
||||
public static class Program
|
||||
|
|
|
|||
|
|
@ -44,8 +44,8 @@ public class PagedApiResult<T> : ApiResult<T> where T : class, new()
|
|||
{
|
||||
return new PagedApiResult<T>(true, message, code, data, totalCount, pageIndex, pageSize);
|
||||
}
|
||||
public static PagedApiResult<T> FailResult(string message = "操作失败")
|
||||
public static PagedApiResult<T> FailResult(string message = "操作失败", int errCode = 500)
|
||||
{
|
||||
return new PagedApiResult<T>(false, message, 500, null, 0, 0, 0);
|
||||
return new PagedApiResult<T>(false, message, errCode, null, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,16 @@ public class OnlineManagementController(IOnlineManagementService service) : Base
|
|||
{
|
||||
int dataTotal = 0;
|
||||
var result = service.GetAllOnlineUser(pageIndex, pageSize, ref dataTotal);
|
||||
return PagedApiResult<List<OnlineDto>>.SuccessResult(result, dataTotal, pageIndex, pageSize);
|
||||
if (result == null || result.Count == 0)
|
||||
{
|
||||
return PagedFail(result, "No data found", 404);
|
||||
}
|
||||
return Success(result, dataTotal, pageIndex, pageSize);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ApiResult<OnlineDto> OnlineRegistered(OnlineDto onlineInfo)
|
||||
{
|
||||
return ApiResult<OnlineDto>.SuccessResult(service.OnlineRegistered(onlineInfo));
|
||||
return Success(service.OnlineRegistered(onlineInfo));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue