You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.8 KiB
C#

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
{
/// <summary>
/// 测试服务
/// </summary>
[ApiDescriptionSettings("Application",Name = "Test", Order = 1)]
public class TestService : ITestService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository<Test> _rep;
public TestService(SqlSugarRepository<Test> rep)
{
_rep = rep;
}
/// <summary>
/// 分页查询测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Test/page")]
public async Task<dynamic> Page([FromQuery] TestInput input)
{
var entities = await _rep.AsQueryable()
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
/// <summary>
/// 增加测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Test/add")]
public async Task Add(AddTestInput input)
{
var entity = input.Adapt<Test>();
await _rep.InsertAsync(entity);
}
/// <summary>
/// 删除测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Test/delete")]
public async Task Delete(DeleteTestInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
/// <summary>
/// 更新测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("/Test/edit")]
public async Task Update(UpdateTestInput input)
{
var entity = input.Adapt<Test>();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
/// <summary>
/// 获取测试
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Test/detail")]
public async Task<Test> Get([FromQuery] QueryeTestInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
/// <summary>
/// 获取测试列表
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpGet("/Test/list")]
public async Task<dynamic> List([FromQuery] TestInput input)
{
return await _rep.ToListAsync();
}
}
}