forked from ddrilling/AsbCloudServer
84 lines
3.4 KiB
C#
84 lines
3.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
{
|
|
[Route("api/admin/permission")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class AdminPermissionController : ControllerBase
|
|
{
|
|
private readonly IPermissionService permissionService;
|
|
|
|
public AdminPermissionController(IPermissionService permissionService)
|
|
{
|
|
this.permissionService = permissionService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получает список всех разрешений для роли
|
|
/// </summary>
|
|
/// <param name="idRole"> id роли </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(IEnumerable<PermissionDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
[Permission]
|
|
public async Task<IActionResult> GetByIdRoleAsync(int idRole, CancellationToken token = default)
|
|
{
|
|
var result = await permissionService.GetByIdRoleAsync(idRole, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Добавляет разрешения для роли
|
|
/// </summary>
|
|
/// <param name="dtos"> Объекты новых разрешений для справочника </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> InsertRangeAsync(IEnumerable<PermissionDto> dtos,
|
|
CancellationToken token = default)
|
|
{
|
|
var result =await permissionService.InsertRangeAsync(dtos, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Обновляет разрешение для роли
|
|
/// </summary>
|
|
/// <param name="dto"> Объект разрешения </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns></returns>
|
|
[HttpPut]
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> UpdateAsync(PermissionDto dto,
|
|
CancellationToken token = default)
|
|
{
|
|
var result = await permissionService.UpdateAsync(dto, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Удаляет разрешение для роли
|
|
/// </summary>
|
|
/// <param name="idPermission"> id разрешения </param>
|
|
/// <param name="idUserRole"> id роли для удаления разрешения </param>
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
/// <returns></returns>
|
|
[HttpDelete("{idPermission}/{idUserRole}")]
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> DeleteAsync(int idUserRole, int idPermission,
|
|
CancellationToken token = default)
|
|
{
|
|
var result = await permissionService.DeleteAsync(idUserRole, idPermission, token);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
} |