forked from sanchezvem/PyroFetes
commentaire endpoint
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user