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

104 lines
4.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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/user/role")]
[ApiController]
[Authorize]
public class AdminUserRoleController : ControllerBase
{
private readonly IUserRoleService userRoleService;
public AdminUserRoleController(IUserRoleService userRoleService)
{
this.userRoleService = userRoleService;
}
/// <summary>
/// Получает список всех доступных ролей
/// </summary>
/// <param name="token">Токен отмены задачи</param>
/// <returns>Список всех доступных ролей</returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<UserRoleDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAllAsync(CancellationToken token = default)
{
// TODO: Как будем делать проверку ролей пользователя? Админ, не админ.
var result = await userRoleService.GetAllAsync(token)
.ConfigureAwait(false);
return Ok(result);
}
/// <summary>
/// Получает информацию о запрашиваемой роли
/// </summary>
/// <param name="idRole">id запрашиваемой задачи</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns>Информацию о запрашиваемой роли</returns>
[HttpGet("{idRole}")]
[ProducesResponseType(typeof(UserRoleDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idRole, CancellationToken token = default)
{
var result = await userRoleService.GetAsync(idRole, token)
.ConfigureAwait(false);
return Ok(result);
}
/// <summary>
/// Добавить запись
/// </summary>
/// <param name="dto">Объект с параметрами добавляемой роли</param>
/// <param name="token">Токен отмены задачи</param>
/// <returns>1 - добавлено, 0 - нет</returns>
[HttpPost]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> Insert([FromBody] UserRoleDto dto,
CancellationToken token = default)
{
var result = await userRoleService.InsertAsync(dto, token)
.ConfigureAwait(false);
return Ok(result);
}
/// <summary>
/// Редактировать запись по id
/// </summary>
/// <param name="dto">Объект с параметрами добавляемой роли</param>
/// <param name="permissionIds">Id добавляемых к роли разрешений</param>
/// <param name="token"></param>
/// <returns>1 - успешно отредактировано, 0 - нет</returns>
[HttpPut("{id}")]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> Update([FromBody] UserRoleDto dto,
CancellationToken token = default)
{
await userRoleService.UpdateAsync(dto, token).ConfigureAwait(false);
return Ok();
}
/// <summary>
/// Удаляет роли по указанным id
/// </summary>
/// <param name="ids">Список id ролей для удаления</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> Update(IEnumerable<int> ids, CancellationToken token = default)
{
var result = await userRoleService.DeleteAsync(ids, token).ConfigureAwait(false);
return Ok(result);
}
}
}