Finalisation endpoints
This commit is contained in:
32
PyroFetes/Endpoints/Truck/GetAllTrucksEndpoint.cs
Normal file
32
PyroFetes/Endpoints/Truck/GetAllTrucksEndpoint.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Truck.Response;
|
||||
|
||||
namespace PyroFetes.Endpoints.Truck;
|
||||
|
||||
public class GetAllTrucksEndpoint(PyroFetesDbContext pyroFetesDbContext) : EndpointWithoutRequest<List<ReadTruckDto>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/api/trucks");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
var trucks = await pyroFetesDbContext.Trucks
|
||||
.Include(t => t.ShowTrucks)
|
||||
.Select(t => new ReadTruckDto
|
||||
{
|
||||
Id = t.Id,
|
||||
Type = t.Type,
|
||||
MaxExplosiveCapacity = t.MaxExplosiveCapacity,
|
||||
Sizes = t.Sizes,
|
||||
Statut = t.Status,
|
||||
ShowId = t.ShowTrucks!.FirstOrDefault() != null ? t.ShowTrucks.FirstOrDefault()!.ShowId : null
|
||||
})
|
||||
.ToListAsync(ct);
|
||||
|
||||
await Send.OkAsync(trucks, ct);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user