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

@@ -11,32 +11,32 @@ public class GetMaterialRequest
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
{
public override void Configure()
public override void Configure() //Configuration de l'endpoint
{
Get("Api/materials/{@id}", x => new { x.Id });
AllowAnonymous();
Get("Api/materials/{@id}", x => new { x.Id }); //Création d'un endpoint qui récupère un matériel grâce à son id
AllowAnonymous(); //Ignorer les requêtes non authentifiées
}
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct) //Méthode asynchrone qui traite la récupération du matériel
{
Models.Material? material = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
Models.Material? material = await pyrofetesdbcontext //Récupère un matériel dans la bdd et le stocke dans material
.Materials //Recherche le matériel dans la table Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); //Recherche un matériel dont l'id correspond à req.Id
if (material == null)
if (material == null) //Si le matériel n'est pas trouvé
{
Console.WriteLine("Aucun matériel avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
Console.WriteLine("Aucun matériel avec l'ID {req.Id} trouvé."); //Afficher aucun matériel avec l'id ... trouvé
await Send.NotFoundAsync(ct); //Renvoie une erreur 404
return; //Arrêt de la méthode
}
GetMaterialDto responseDto = new()
GetMaterialDto responseDto = new() //Constuire l'objet de réponse pour retourner id, label et warehouseId à l'utilisateur
{
Id = material.Id,
Label = material.Name,
WarehouseId = material.WarehouseId,
Id = material.Id, //Affiche l'id lors de la réponse
Label = material.Name, //Affiche le label lors de la réponse
WarehouseId = material.WarehouseId, //Affiche warehouseId lors de la réponse
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client
}
}