using PF3.DTO.Truck.Request; using PF3.DTO.Truck.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; using PF3; namespace PF3.Endpoints.Truck; public class UpdateTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint { public override void Configure() { Put("/api/trucks/{id}"); } public override async Task HandleAsync(UpdateTruckDto req, CancellationToken ct) { var id = Route("id"); var truck = await pf3DbContext.Trucks.FirstOrDefaultAsync(t => t.Id == id, ct); if (truck is null) { await Send.NotFoundAsync(ct); return; } truck.Type = req.Type; truck.MaxExplosiveCapacity = req.MaxExplosiveCapacity; truck.Sizes = req.Sizes; truck.Statut = req.Statut; truck.ShowId = req.ShowId; await pf3DbContext.SaveChangesAsync(ct); var result = new ReadTruckDto { Id = truck.Id, Type = truck.Type, MaxExplosiveCapacity = truck.MaxExplosiveCapacity, Sizes = truck.Sizes, Statut = truck.Statut, ShowId = truck.ShowId }; await Send.OkAsync(result, ct); } }