Files
parr_api/PARR.API/Controllers/V1/RoleController.cs
2023-12-05 16:32:34 +10:00

45 lines
1.3 KiB
C#

using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using PARR.API.Contracts.V1;
using PARR.API.Contracts.V1.Responses;
using PARR.API.Contracts.V1.Responses.Base;
using PARR.API.Controllers.V1.Base;
using PARR.Constants;
using PARR.DAL.Services.Interfaces;
namespace PARR.API.Controllers.V1
{
[Authorize(Roles = ParrRoles.Administrator.Role)]
public class RoleController : BaseApiController
{
private readonly IRoleService roleService;
private readonly IMapper mapper;
public RoleController(
IRoleService roleService,
IMapper mapper
)
{
this.roleService = roleService;
this.mapper = mapper;
}
/// <summary>
/// Список ролей пользователей
/// </summary>
/// <returns></returns>
[HttpGet(ApiRoutes.Role.GetAll)]
public async Task<IActionResult> GetAll()
{
var roles = await roleService.Get().OrderBy(t => t.Description).ToListAsync();
var response = mapper.Map<List<RoleResponse>>(roles);
return Ok(new Response<List<RoleResponse>>(response, true));
}
}
}