Files
AP-WEB-PF3/PF3/Endpoints/Truck/GetAllTruckEndpoint.cs
2025-10-16 17:00:36 +02:00

33 lines
878 B
C#

using PF3.DTO.Truck.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace PF3.Endpoints.Truck;
public class GetAllTrucksEndpoint(PF3DbContext pf3DbContext) : EndpointWithoutRequest<List<ReadTruckDto>>
{
public override void Configure()
{
Get("/api/trucks");
}
public override async Task HandleAsync(CancellationToken ct)
{
var trucks = await pf3DbContext.Trucks.ToListAsync(ct);
var result = trucks
.Select(truck => new ReadTruckDto
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Statut,
ShowId = truck.ShowId
})
.ToList();
await Send.OkAsync(result, ct);
}
}