mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Refactor controller methods to return ActionResult for better error handling
This commit is contained in:
@@ -78,29 +78,31 @@ public class ScreensByMachineController(MarechaiContext context) : ControllerBas
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task DeleteAsync(long id)
|
||||
public async Task<ActionResult> DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
if(userId is null) return Unauthorized();
|
||||
ScreensByMachine item = await context.ScreensByMachine.FindAsync(id);
|
||||
|
||||
if(item is null) return;
|
||||
if(item is null) return NotFound();
|
||||
|
||||
context.ScreensByMachine.Remove(item);
|
||||
|
||||
await context.SaveChangesWithUserAsync(userId);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<long> CreateAsync(int machineId, int screenId)
|
||||
public async Task<ActionResult<long>> CreateAsync(int machineId, int screenId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
if(userId is null) return Unauthorized();
|
||||
if(context.ScreensByMachine.Any(s => s.MachineId == machineId && s.ScreenId == screenId)) return 0;
|
||||
|
||||
var item = new ScreensByMachine
|
||||
|
||||
Reference in New Issue
Block a user