45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using OrdersManagementDataModel.Dtos;
|
|
using OrdersManagementDataModel.Services;
|
|
|
|
namespace FaKrosnoApi.Controllers;
|
|
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class RolesController(IRoleService service) : Controller
|
|
{
|
|
[HttpGet]
|
|
public async Task<ActionResult<IEnumerable<RoleDto>>> GetAll()
|
|
{
|
|
IEnumerable<RoleDto?> roles = await service.GetAll();
|
|
return Ok(roles);
|
|
}
|
|
|
|
[HttpGet("by-id")]
|
|
public async Task<ActionResult<RoleDto?>> GetById([FromQuery] Guid id)
|
|
{
|
|
RoleDto? role = await service.GetById(id);
|
|
return role != null ? Ok(role) : NotFound();
|
|
}
|
|
|
|
[HttpGet("by-name")]
|
|
public async Task<ActionResult<RoleDto?>> GetByName([FromQuery] string name)
|
|
{
|
|
RoleDto? role = await service.GetByName(name);
|
|
return role != null ? Ok(role) : NotFound();
|
|
}
|
|
|
|
[HttpPost]
|
|
public async Task<ActionResult<RoleDto>> Add([FromBody] RoleDto role)
|
|
{
|
|
await service.Add(role);
|
|
return Ok(role);
|
|
}
|
|
|
|
[HttpDelete]
|
|
public async Task<ActionResult<RoleDto>> Delete([FromQuery] Guid id)
|
|
{
|
|
await service.Delete(id);
|
|
return Ok();
|
|
}
|
|
} |