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

39 lines
1006 B
C#

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