2021-11-24 17:38:40 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data;
|
2021-09-10 11:28:57 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/admin/user/role")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
2021-11-24 17:38:40 +05:00
|
|
|
|
public class AdminUserRoleController : ControllerBase
|
2021-09-10 11:28:57 +05:00
|
|
|
|
{
|
2021-11-24 17:38:40 +05:00
|
|
|
|
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)
|
2021-09-10 11:28:57 +05:00
|
|
|
|
{
|
|
|
|
|
|
2021-11-24 17:38:40 +05:00
|
|
|
|
var result = await userRoleService.DeleteAsync(ids, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
2021-09-10 11:28:57 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|