Use transactions

This commit is contained in:
lumijiez
2025-06-10 23:49:14 +03:00
parent db61171ada
commit 09f1668351
11 changed files with 73 additions and 76 deletions

View File

@@ -27,7 +27,6 @@ public class UserController(IMediator mediator) : ControllerBase
};
await mediator.Send(new SyncUserCommand(auth0User));
return Ok("User Synced.");
}
}

View File

@@ -14,35 +14,21 @@ public class UserRoleController(IMediator mediator) : ControllerBase
[HttpGet("me")]
public async Task<IActionResult> GetMyRoles()
{
var claims = User.Claims as Claim[] ?? User.Claims.ToArray();
var sub = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value ?? string.Empty;
var myRoles = await mediator.Send(new GetUserRolesCommand(sub));
return Ok(myRoles);
var sub = User.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? string.Empty;
return Ok(await mediator.Send(new GetUserRolesCommand(sub)));
}
[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);
return Ok(await mediator.Send(command));
}
[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);
return Ok(await mediator.Send(command));
}
}