Add Role unsetting functionality

This commit is contained in:
lumijiez
2025-06-10 22:54:09 +03:00
parent 85d469e576
commit b8ddee390a
2 changed files with 43 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ namespace Imprink.WebApi.Controllers.Users;
public class UserRoleController(IMediator mediator) : ControllerBase
{
[Authorize]
[HttpGet("me")]
[HttpGet("/me")]
public async Task<IActionResult> GetMyRoles()
{
var claims = User.Claims as Claim[] ?? User.Claims.ToArray();
@@ -23,7 +23,7 @@ public class UserRoleController(IMediator mediator) : ControllerBase
}
[Authorize(Roles = "Admin")]
[HttpPost("set")]
[HttpPost("/set")]
public async Task<IActionResult> SetUserRole(SetUserRoleCommand command)
{
var userRole = await mediator.Send(command);
@@ -33,4 +33,16 @@ public class UserRoleController(IMediator mediator) : ControllerBase
return Ok(userRole);
}
[Authorize(Roles = "Admin")]
[HttpPost("/unset")]
public async Task<IActionResult> UnsetUserRole(DeleteUserRoleCommand command)
{
var userRole = await mediator.Send(command);
if (userRole == null)
return BadRequest();
return Ok(userRole);
}
}