using API.DTO.Brand.Response; using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Brand; public class GetBrandRequest { public int Id { get; set; } } public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint { public override void Configure() { Get("/api/brands/{@id}", x => new { x.Id }); AllowAnonymous(); } public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct) { Models.Brand? brand = await pyrofetesdbcontext .Brands .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); if (brand == null) { Console.WriteLine($"Aucune marque avec l'ID {req.Id} trouvé."); await Send.NotFoundAsync(ct); return; } GetBrandDto responseDto = new() { Id = req.Id, Name = brand.Name }; await Send.OkAsync(responseDto, ct); } }