DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AdminPermissionController.cs

83 lines
3.4 KiB
C#
Raw Normal View History

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
{
2021-12-03 09:44:10 +05:00
[Route("api/admin/permission")]
[ApiController]
[Authorize]
public class AdminPermissionController : ControllerBase
{
private readonly IPermissionService permissionService;
2021-12-03 09:44:10 +05:00
public AdminPermissionController(IPermissionService permissionService)
{
this.permissionService = permissionService;
}
/// <summary>
/// Получает список всех разрешений для роли
/// </summary>
/// <param name="idRole"> id роли </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
2021-12-03 09:44:10 +05:00
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<PermissionDto>), (int)System.Net.HttpStatusCode.OK)]
2021-12-03 09:44:10 +05:00
public async Task<IActionResult> GetByIdRoleAsync(int idRole, CancellationToken token = default)
{
2021-12-03 09:44:10 +05:00
var result = await permissionService.GetByIdRoleAsync(idRole, token);
return Ok(result);
}
/// <summary>
/// Добавляет разрешения для роли
/// </summary>
/// <param name="dtos"> Объекты новых разрешений для справочника </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
2021-12-03 09:44:10 +05:00
[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);
}
2021-12-03 09:44:10 +05:00
/// <summary>
2021-12-03 09:44:10 +05:00
/// Обновляет разрешение для роли
/// </summary>
/// <param name="dto"> Объект разрешения для справочника </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
2021-12-03 09:44:10 +05:00
[HttpPut]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
2021-12-03 09:44:10 +05:00
public async Task<IActionResult> UpdateAsync(PermissionDto dto,
CancellationToken token = default)
{
2021-12-03 09:44:10 +05:00
var result = await permissionService.UpdateAsync(dto, token);
return Ok(result);
}
2021-12-03 09:44:10 +05:00
/// <summary>
/// Удаляет разрешение для роли
/// </summary>
/// <param name="idPermission"> id разрешения </param>
2021-12-03 09:44:10 +05:00
/// <param name="idUserRole"> id роли для удаления разрешения </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
2021-12-03 09:44:10 +05:00
[HttpDelete("{idPermission}/{idRole}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
2021-12-03 09:44:10 +05:00
public async Task<IActionResult> DeleteAsync(int idUserRole, int idPermission,
CancellationToken token = default)
{
2021-12-03 09:44:10 +05:00
var result = await permissionService.DeleteAsync(idUserRole, idPermission, token);
return Ok(result);
}
}
}