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,48 @@
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<UpdateTruckDto, ReadTruckDto>
{
public override void Configure()
{
Put("/api/trucks/{id}");
}
public override async Task HandleAsync(UpdateTruckDto req, CancellationToken ct)
{
var id = Route<int>("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);
}
}