Endopoint presque fini

This commit is contained in:
2025-10-16 17:00:36 +02:00
parent 8d0c2aa3f6
commit ec5149b6da
28 changed files with 551 additions and 31 deletions

View File

@@ -0,0 +1,39 @@
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace PF3.Endpoints.Truck;
public class GetTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdTruckDto, ReadTruckDto>
{
public override void Configure()
{
Get("/api/trucks/{@Id}");
}
public override async Task HandleAsync(IdTruckDto req, CancellationToken ct)
{
var truck = await pf3DbContext.Trucks
.Where(t => t.Id == req.Id)
.Select(t => new ReadTruckDto
{
Id = t.Id,
Type = t.Type,
MaxExplosiveCapacity = t.MaxExplosiveCapacity,
Sizes = t.Sizes,
Statut = t.Statut,
ShowId = t.ShowId
})
.FirstOrDefaultAsync(ct);
if (truck is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(truck, ct);
}
}