更新基类控制器
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class BaseCrudController<T> : ControllerBase where T : class,new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
|
||||
public IRepository<T> _iRepository;
|
||||
public BaseCrudController(ILogger<T> logger, IRepository<T> iRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_iRepository = iRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<Result> Get()
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.GetListAsync());
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<Result> Page(QueryCondition queryCondition)
|
||||
{
|
||||
return Result.Success().SetData(_iRepository.CommonPage(queryCondition));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(T entity)
|
||||
{
|
||||
return Result.Success().SetData(await _iRepository.InsertReturnEntityAsync(entity));
|
||||
}
|
||||
[HttpPut]
|
||||
public async Task<Result> Update(T entity)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.UpdateAsync(entity));
|
||||
}
|
||||
[HttpDelete]
|
||||
public async Task<Result> Delete(object[] ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRepository.DeleteByIdsAsync(ids));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
@@ -15,26 +16,16 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class UserController : ControllerBase
|
||||
public class UserController : BaseCrudController<UserEntity>
|
||||
{
|
||||
private readonly ILogger<UserController> _logger;
|
||||
|
||||
private IUserService _iUserService;
|
||||
public UserController(ILogger<UserController> logger, IUserService iUserService)
|
||||
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
||||
{
|
||||
_logger = logger;
|
||||
_iUserService = iUserService;
|
||||
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<Result> Get()
|
||||
public async Task<IActionResult> Test()
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetListAsync());
|
||||
}
|
||||
[HttpPost]
|
||||
public async Task<Result> Add(UserEntity userEntity)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.InsertAsync(userEntity));
|
||||
return Ok(await _iRepository.GetListAsync());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user