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

40 lines
1.0 KiB
C#

using FastEndpoints;
using PF3.DTO.Truck.Request;
using PF3.DTO.Truck.Response;
namespace PF3.Endpoints.Truck;
public class CreateTruckEndpoint(PF3DbContext pf3DbContext):Endpoint<CreateTruckDto, ReadTruckDto>
{
public override void Configure()
{
Post("/api/truck");
AllowAnonymous();
}
public override async Task HandleAsync(CreateTruckDto req, CancellationToken ct)
{
var truck = new Models.Truck
{
Type = req.Type,
MaxExplosiveCapacity = req.MaxExplosiveCapacity,
Sizes = req.Sizes,
Statut = req.Statut
};
pf3DbContext.Trucks.Add(truck);
await pf3DbContext.SaveChangesAsync(ct);
var result = new ReadTruckDto()
{
Id = truck.Id,
Type = truck.Type,
MaxExplosiveCapacity = truck.MaxExplosiveCapacity,
Sizes = truck.Sizes,
Statut = truck.Statut
};
await Send.OkAsync(result, ct);
}
}