接口名称简化
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Yi.Framework.Common.Helper;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Language;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Query;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Json To Sql 类比模式,通用模型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
[ApiController]
|
||||
public class BaseSimpleRdController<T> : ControllerBase where T : class, new()
|
||||
{
|
||||
private readonly ILogger<T> _logger;
|
||||
private IBaseService<T> _baseService;
|
||||
private IRepository<T> _repository;
|
||||
public BaseSimpleRdController(ILogger<T> logger, IBaseService<T> iBaseService)
|
||||
{
|
||||
_logger = logger;
|
||||
_baseService = iBaseService;
|
||||
_repository = iBaseService._repository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主键查询
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[Route("{id}")]
|
||||
[HttpGet]
|
||||
public virtual async Task<Result> GetById([FromRoute]long id)
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetByIdAsync(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全部列表查询
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:get")]
|
||||
[HttpGet]
|
||||
public virtual async Task<Result> GetList()
|
||||
{
|
||||
return Result.Success().SetData(await _repository.GetListAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 列表删除
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(T)}:del")]
|
||||
[HttpDelete]
|
||||
public virtual async Task<Result> DelList(List<long> ids)
|
||||
{
|
||||
return Result.Success().SetStatus(await _repository.DeleteByIdsAsync(ids.ToDynamicArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class RoleController : BaseSimpleCrudController<RoleEntity>
|
||||
public class RoleController : BaseSimpleRdController<RoleEntity>
|
||||
{
|
||||
private IRoleService _iRoleService;
|
||||
public RoleController(ILogger<RoleEntity> logger, IRoleService iRoleService) : base(logger, iRoleService)
|
||||
@@ -52,15 +52,6 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过角色id来获取菜单列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> GetInMenuByRoleId(long RoleId)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色包含菜单
|
||||
@@ -69,7 +60,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
public async Task<Result> AddInfo(RoleInfoDto roleDto)
|
||||
public async Task<Result> Add(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetData(await _iRoleService.AddInfo(roleDto));
|
||||
}
|
||||
@@ -79,7 +70,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateInfo(RoleInfoDto roleDto)
|
||||
public async Task<Result> Update(RoleInfoDto roleDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iRoleService.UpdateInfo(roleDto));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class UserController : BaseSimpleCrudController<UserEntity>
|
||||
public class UserController : BaseSimpleRdController<UserEntity>
|
||||
{
|
||||
private IUserService _iUserService;
|
||||
public UserController(ILogger<UserEntity> logger, IUserService iUserService) : base(logger, iUserService)
|
||||
@@ -55,22 +55,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加用户,去重,密码加密
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
[Permission($"{nameof(UserEntity)}:add")]
|
||||
[HttpPost]
|
||||
public override async Task<Result> Add(UserEntity entity)
|
||||
{
|
||||
if (!await _iUserService.Exist(entity.UserName))
|
||||
{
|
||||
entity.BuildPassword();
|
||||
return Result.Success().SetData(await _iUserService._repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
}
|
||||
return Result.SuccessError("用户已存在");
|
||||
}
|
||||
///// <summary>
|
||||
///// 添加用户,去重,密码加密
|
||||
///// </summary>
|
||||
///// <param name="entity"></param>
|
||||
///// <returns></returns>
|
||||
//[Permission($"{nameof(UserEntity)}:add")]
|
||||
//[HttpPost]
|
||||
//public async Task<Result> Add(UserEntity entity)
|
||||
//{
|
||||
// if (!await _iUserService.Exist(entity.UserName))
|
||||
// {
|
||||
// entity.BuildPassword();
|
||||
// return Result.Success().SetData(await _iUserService._repository.InsertReturnSnowflakeIdAsync(entity));
|
||||
// }
|
||||
// return Result.SuccessError("用户已存在");
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 给多用户设置多角色
|
||||
@@ -87,21 +87,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <summary>
|
||||
/// 通过用户id得到用户信息关联部门、岗位、角色
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("{id}")]
|
||||
public override async Task<Result> GetById(long id)
|
||||
public override async Task<Result> GetById([FromRoute] long id)
|
||||
{
|
||||
return Result.Success().SetData(await _iUserService.GetInfoById(id));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户信息
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> UpdateInfo(UserInfoDto userDto)
|
||||
public async Task<Result> Update(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.UpdateInfo(userDto));
|
||||
}
|
||||
@@ -109,13 +110,19 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <summary>
|
||||
/// 添加用户
|
||||
/// </summary>
|
||||
/// <param name="userDto"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<Result> AddInfo(UserInfoDto userDto)
|
||||
public async Task<Result> Add(UserInfoDto userDto)
|
||||
{
|
||||
return Result.Success().SetStatus(await _iUserService.AddInfo(userDto));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重置密码
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPut]
|
||||
public async Task<Result> RestPassword(UserEntity user)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user