mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Refactor controller methods to use synchronous Task return types for improved readability
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
// Copyright © 2003-2025 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
@@ -34,7 +33,6 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace Marechai.Server.Controllers;
|
||||
|
||||
@@ -46,17 +44,17 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
|
||||
[AllowAnonymous]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<List<MagazineByMachineDto>> GetByMagazine(long bookId) => await context.MagazinesByMachines
|
||||
.Where(p => p.MagazineId == bookId)
|
||||
.Select(p => new MagazineByMachineDto
|
||||
{
|
||||
Id = p.Id,
|
||||
MagazineId = p.MagazineId,
|
||||
MachineId = p.MachineId,
|
||||
Machine = p.Machine.Name
|
||||
})
|
||||
.OrderBy(p => p.Machine)
|
||||
.ToListAsync();
|
||||
public Task<List<MagazineByMachineDto>> GetByMagazine(long bookId) => context.MagazinesByMachines
|
||||
.Where(p => p.MagazineId == bookId)
|
||||
.Select(p => new MagazineByMachineDto
|
||||
{
|
||||
Id = p.Id,
|
||||
MagazineId = p.MagazineId,
|
||||
MachineId = p.MachineId,
|
||||
Machine = p.Machine.Name
|
||||
})
|
||||
.OrderBy(p => p.Machine)
|
||||
.ToListAsync();
|
||||
|
||||
[HttpDelete]
|
||||
[Authorize(Roles = "Admin,UberAdmin")]
|
||||
@@ -65,6 +63,7 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return;
|
||||
MagazinesByMachine item = await context.MagazinesByMachines.FindAsync(id);
|
||||
|
||||
@@ -82,7 +81,9 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
|
||||
public async Task<long> CreateAsync(int machineId, long bookId)
|
||||
{
|
||||
string userId = User.FindFirstValue(ClaimTypes.Sid);
|
||||
|
||||
if(userId is null) return 0;
|
||||
|
||||
var item = new MagazinesByMachine
|
||||
{
|
||||
MachineId = machineId,
|
||||
@@ -94,4 +95,4 @@ public class MagazinesByMachineController(MarechaiContext context) : ControllerB
|
||||
|
||||
return item.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user