Endopoint presque fini
This commit is contained in:
40
PF3/Endpoints/Truck/CreateTruckEndpoint.cs
Normal file
40
PF3/Endpoints/Truck/CreateTruckEndpoint.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user