Add UserRole handling

This commit is contained in:
lumijiez
2025-06-10 22:10:16 +03:00
parent beaacffb9a
commit a25459d2cb
15 changed files with 92 additions and 143 deletions

View File

@@ -1,6 +1,7 @@
using System.Security.Claims;
using Imprink.Application.Users;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Imprink.WebApi.Controllers.Users;
@@ -9,7 +10,7 @@ namespace Imprink.WebApi.Controllers.Users;
[Route("/api/users/roles")]
public class UserRoleController(IMediator mediator) : ControllerBase
{
//[Authorize]
[Authorize]
[HttpGet("me")]
public async Task<IActionResult> GetMyRoles()
{
@@ -20,4 +21,16 @@ public class UserRoleController(IMediator mediator) : ControllerBase
return Ok(myRoles);
}
[Authorize(Roles = "Admin")]
[HttpPost("set")]
public async Task<IActionResult> SetUserRole(SetUserRoleCommand command)
{
var userRole = await mediator.Send(command);
if (userRole == null)
return BadRequest();
return Ok(userRole);
}
}