commentaire endpoint

This commit is contained in:
2025-11-05 22:38:55 +01:00
parent 4c0e7df9de
commit 3c32baac57
45 changed files with 475 additions and 479 deletions

View File

@@ -13,30 +13,30 @@ public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<G
{
public override void Configure()
{
Get("/api/brands/{@id}", x => new { x.Id });
AllowAnonymous();
Get("/api/brands/{@id}", x => new { x.Id }); //endpoint qui affiche la marque en fonction de l'id
AllowAnonymous(); //Autorise l'accès sans authentification
}
public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct)
{
Models.Brand? brand = await pyrofetesdbcontext
.Brands
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
Models.Brand? brand = await pyrofetesdbcontext //Récupère la table marque dans la bdd
.Brands
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //récupère l'id
if (brand == null)
{
Console.WriteLine($"Aucune marque avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
await Send.NotFoundAsync(ct); //Renvoie une erreur 404
return; //Arrêt de la méthode
}
GetBrandDto responseDto = new()
GetBrandDto responseDto = new() //renvoie l'id et le nom
{
Id = req.Id,
Name = brand.Name
Id = req.Id, //Affiche l'id
Name = brand.Name //Affiche le nom
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client
}
}