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

24 lines
644 B
C#

using PF3.DTO.Truck.Request;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PF3;
namespace ApiLibrary.Endpoints.Truck;
public class DeleteTruckEndpoint(PF3DbContext pf3DbContext) : Endpoint<IdTruckDto>
{
public override void Configure()
{
Delete("/api/trucks/{@Id}", x => new { x.Id });
}
public override async Task HandleAsync(IdTruckDto req, CancellationToken ct)
{
var truck = await pf3DbContext.Trucks.FirstOrDefaultAsync(a => a.Id == req.Id, ct);
pf3DbContext.Trucks.Remove(truck);
await pf3DbContext.SaveChangesAsync(ct);
await Send.OkAsync(ct);
}
}