using Magic.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System.Linq;
using System.Threading.Tasks;
using Magic.Application.Entity;
namespace Magic.Application
{
///
/// 测试服务
///
[ApiDescriptionSettings("Application",Name = "Test", Order = 1)]
public class TestService : ITestService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public TestService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询测试
///
///
///
[HttpGet("/Test/page")]
public async Task Page([FromQuery] TestInput input)
{
var entities = await _rep.AsQueryable()
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加测试
///
///
///
[HttpPost("/Test/add")]
public async Task Add(AddTestInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 删除测试
///
///
///
[HttpPost("/Test/delete")]
public async Task Delete(DeleteTestInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新测试
///
///
///
[HttpPost("/Test/edit")]
public async Task Update(UpdateTestInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
///
/// 获取测试
///
///
///
[HttpGet("/Test/detail")]
public async Task Get([FromQuery] QueryeTestInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 获取测试列表
///
///
///
[HttpGet("/Test/list")]
public async Task List([FromQuery] TestInput input)
{
return await _rep.ToListAsync();
}
}
}