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