From 3c32baac5750cc72f2055a5ff942758b9e8c003c Mon Sep 17 00:00:00 2001 From: kieva Date: Wed, 5 Nov 2025 22:38:55 +0100 Subject: [PATCH] commentaire endpoint --- .../Endpoints/Brand/CreateBrandEndpoint.cs | 22 ++++++------ .../Endpoints/Brand/DeleteBrandEndpoint.cs | 26 +++++++------- .../Endpoints/Brand/GetAllBrandsEndpoint.cs | 16 ++++----- PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs | 22 ++++++------ .../Endpoints/Brand/UpdateBrandEndpoint.cs | 14 ++++---- .../CreateClassificationEndpoint.cs | 18 +++++----- .../DeleteClassificationEndpoint.cs | 20 +++++------ .../GetAllClassificationsEndpoint.cs | 16 ++++----- .../GetClassificationEndpoint.cs | 18 +++++----- .../UpdateClassificationEndpoint.cs | 14 ++++---- .../Endpoints/Color/CreateColorEndpoint.cs | 2 +- .../Endpoints/Color/DeleteColorEndpoint.cs | 32 ++++++++--------- .../Endpoints/Color/GetAllColorsEndpoint.cs | 18 +++++----- PyroFetes/Endpoints/Color/GetColorEndpoint.cs | 31 ++++++++-------- .../Endpoints/Color/UpdateColorEndpoint.cs | 32 ++++++++--------- .../Endpoints/Effect/CreateEffectEndpoint.cs | 24 ++++++------- .../Endpoints/Effect/DeleteEffectEndpoint.cs | 28 +++++++-------- .../Endpoints/Effect/GetAllEffectsEndpoint.cs | 18 +++++----- .../Endpoints/Effect/GetEffectEndpoint.cs | 32 ++++++++--------- .../Endpoints/Effect/UpdateEffectEndpoint.cs | 35 +++++++++--------- .../Endpoints/Login/CreateLoginEndpoint.cs | 18 +++++----- .../Material/CreateMaterialEndpoint.cs | 26 +++++++------- .../Material/DeleteMaterialEndpoint.cs | 34 +++++++++--------- .../Material/GetAllMaterialsEndpoint.cs | 22 ++++++------ .../Endpoints/Material/GetMaterialEndpoint.cs | 32 ++++++++--------- .../Material/UpdateMaterialEndpoint.cs | 36 +++++++++---------- .../Movement/CreateMovementEndpoint.cs | 28 +++++++-------- .../Movement/DeleteMovementEndpoint.cs | 32 ++++++++--------- .../Movement/GetAllMovementsEndpoint.cs | 24 ++++++------- .../Endpoints/Movement/GetMovementEndpoint.cs | 36 +++++++++---------- .../Movement/UpdateMovementEndpoint.cs | 16 ++++----- .../Product/CreateProductEndpoint.cs | 24 ++++++------- .../Product/DeleteProductEndpoint.cs | 14 ++++---- .../CreateProductCategoryEndpoint.cs | 18 +++++----- .../DeleteProductCategoryEndpoint.cs | 20 +++++------ .../GetAllProductCategoriesEndpoint.cs | 16 ++++----- .../GetProductCategoryEndpoint.cs | 22 ++++++------ .../UpdateProductCategoryEndpoint.cs | 26 +++++++------- .../Supplier/CreateSupplierEndpoint.cs | 20 +++++------ .../Supplier/DeleteSupplierEndpoint.cs | 16 ++++----- .../Supplier/GetAllSupplierEndpoint.cs | 4 +-- .../Endpoints/Supplier/GetSupplierEndpoint.cs | 8 ++--- .../Supplier/UpdateSupplierEndpoint.cs | 4 +-- .../Warehouse/CreateWarehouseEndpoint.cs | 18 +++++----- .../Warehouse/DeleteWarehouseEndpoint.cs | 2 +- 45 files changed, 475 insertions(+), 479 deletions(-) diff --git a/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs index 4ff5724..c4d677b 100644 --- a/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs @@ -4,32 +4,32 @@ using PyroFetes.DTO.Brand.Request; namespace PyroFetes.Endpoints.Brand; -public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateBrandDto et l'élement de réponse GetBrandDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/brands"); - AllowAnonymous(); + Post("/api/brands"); //Créer une marque + AllowAnonymous(); //Autorise l'accès sans authentification } - public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct) + public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct) { - Models.Brand brand = new () + Models.Brand brand = new () //Création d'un nom rentré par l'utilisateur { Name = req.Name }; - pyrofetesdbcontext.Brands.Add(brand); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Brands.Add(brand); //Ajout de la marque à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde de la marque dans la bdd Console.WriteLine("Marque créé avec succès !"); - GetBrandDto responseDto = new () + GetBrandDto responseDto = new () //Renvoie le nom { - Name = req.Name + Name = req.Name }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Réponse au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs index eb4fa26..d4a6d5c 100644 --- a/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs @@ -5,34 +5,34 @@ namespace PyroFetes.Endpoints.Brand; public class DeleteBrandRequest { - public int Id { get; set; } + public int Id { get; set; } //Création d'un Id } -public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête DeleteBrandDto. { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Delete("/api/brands/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/brands/{@id}", x => new { x.Id }); //Supprime une marque + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct) { - Models.Brand? brandToDelete = await pyrofetesdbcontext - .Brands - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Brand? brandToDelete = await pyrofetesdbcontext //Récupère une marque dans la bdd et le stocke dans brandToDelete + .Brands //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //Recherche une couleur dont l'id correspond à req.Id if (brandToDelete == 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 } - pyrofetesdbcontext.Brands.Remove(brandToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Brands.Remove(brandToDelete); //Supprime la marque de la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde de la marque dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs b/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs index 2f7be29..010e52a 100644 --- a/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs @@ -8,21 +8,21 @@ public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo { public override void Configure() { - Get("/api/brands"); - AllowAnonymous(); + Get("/api/brands"); //Endpoint qui affiche toutes les marques + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Brands - .Select(a => new GetBrandDto + List responseDto = await pyrofetesdbcontext.Brands //Création d'une liste qui récupère toutes les marques dans la bdd + .Select(a => new GetBrandDto //Sélectionne dans la liste chaque marque { - Id = a.Id, - Name = a.Name, + Id = a.Id, //Affiche l'id + Name = a.Name, //Affiche le nom } - ).ToListAsync(ct); + ).ToListAsync(ct); //Retourne la liste de marque - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs index 0e8dc22..f40deed 100644 --- a/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs @@ -13,30 +13,30 @@ public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs index 6d4ce06..9b5e4dc 100644 --- a/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs @@ -8,27 +8,27 @@ public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi { public override void Configure() { - Put("/api/brands/{Id}"); - AllowAnonymous(); + Put("/api/brands/{Id}"); //Met à jour la marque en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct) { - Models.Brand brand = new() + Models.Brand brand = new() //Met à jour la marque { Name = req.Name }; - pyrofetesdbcontext.Add(brand); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Add(brand); //ajoute la marque dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements - GetBrandDto response = new() + GetBrandDto response = new() //renvoie l'id et le nom { Id = req.Id, Name = req.Name }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs index 34184dc..6df6751 100644 --- a/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs @@ -4,32 +4,32 @@ using FastEndpoints; namespace PyroFetes.Endpoints.Classification; -public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateClassificationDto et l'élement de réponse GetClassificationDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/classifications"); - AllowAnonymous(); + Post("/api/classifications"); //Créer une classification + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct) { - Models.Classification classification = new () + Models.Classification classification = new () //Création d'un label rentré par l'utilisateur { Label = req.Label }; - pyrofetesdbcontext.Classifications.Add(classification); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Classifications.Add(classification); //Ajout de la classification à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde de la classification dans la bdd Console.WriteLine("Classification créée avec succès !"); - GetClassificationDto responseDto = new () + GetClassificationDto responseDto = new () //Renvoie le label de la classification { Label = req.Label }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Réponse au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs index 0982278..38af98a 100644 --- a/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs @@ -12,27 +12,27 @@ public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) : { public override void Configure() { - Delete("/api/classifications/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/classifications/{@id}", x => new { x.Id }); //Supprime une classification en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct) { - Models.Classification? classificationToDelete = await libraryDbContext - .Classifications - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Classification? classificationToDelete = await libraryDbContext //Récupère une classification dans la bdd et le stocke dans classificationToDelete + .Classifications //Recherche la classification dans la table Classifications + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //Recherche une classification dont l'id correspond à req.Id if (classificationToDelete == null) { Console.WriteLine($"Aucune classification 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 } - libraryDbContext.Classifications.Remove(classificationToDelete); - await libraryDbContext.SaveChangesAsync(ct); + libraryDbContext.Classifications.Remove(classificationToDelete); //Supprime la classification dans la bdd + await libraryDbContext.SaveChangesAsync(ct); //Sauvegarde de la classification dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs b/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs index b96ab3a..db723f0 100644 --- a/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs @@ -8,21 +8,21 @@ public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext { public override void Configure() { - Get("/api/classifications"); - AllowAnonymous(); + Get("/api/classifications"); //Endpoint qui affiche toutes les classifications + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Classifications - .Select(a => new GetClassificationDto + List responseDto = await pyrofetesdbcontext.Classifications //Création d'une liste qui récupère toutes les classifications dans la bdd + .Select(a => new GetClassificationDto //Sélectionne dans la liste chaque classification { - Id = a.Id, - Label = a.Label, + Id = a.Id, //Récupère l'id + Label = a.Label, //Récupère le label } - ).ToListAsync(ct); + ).ToListAsync(ct); //Retourne la liste de classification - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs index fd7dafd..74e8708 100644 --- a/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs @@ -13,30 +13,30 @@ public class GetClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) :E { public override void Configure() { - Get("/api/classifications/{@id}", x => new { x.Id }); - AllowAnonymous(); + Get("/api/classifications/{@id}", x => new { x.Id }); //endpoint qui affiche la classification en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(GetClassificationRequest req, CancellationToken ct) { - Models.Classification? classification = await pyrofetesdbcontext + Models.Classification? classification = await pyrofetesdbcontext //Récupère la table marque dans la bdd .Classifications - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //récupère l'id if (classification == null) { Console.WriteLine($"Aucune classification 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 } GetClassificationDto responseDto = new() { - Id = req.Id, - Label = classification.Label + Id = req.Id, //Affiche l'id + Label = classification.Label //Affiche le nom }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs index 8569cc7..6a70b6a 100644 --- a/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs @@ -8,27 +8,27 @@ public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) { public override void Configure() { - Put("/api/classifications"); - AllowAnonymous(); + Put("/api/classifications"); //Met à jour la classification en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct) { - Models.Classification classification = new() + Models.Classification classification = new() //Met à jour la classification { Label = req.Label }; - pyrofetesdbcontext.Add(classification); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Add(classification); //ajoute la classification dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements - GetClassificationDto response = new() + GetClassificationDto response = new() //renvoie l'id et le nom { Id = req.Id, Label = req.Label }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs b/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs index 7d9ee6e..a96fd61 100644 --- a/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs @@ -15,7 +15,7 @@ public class CreateColorEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi public override async Task HandleAsync(CreateColorDto req, CancellationToken ct) //La méthode HandleAsync est appelée lorsqu'une requête est envoyée à l'endpoint { - PyroFetes.Models.Color color = new() + PyroFetes.Models.Color color = new() //Création d'un label rentré par l'utilisateur { Label = req.Label, }; diff --git a/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs b/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs index 2b4713d..46d6a1b 100644 --- a/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs @@ -3,35 +3,35 @@ using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Color; -public class DeleteColorRequest +public class DeleteColorRequest //Création d'une classe DeleteColorRequest { - public int Id { get; set; } + public int Id { get; set; } //Création d'un Id } -public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête DeleteColorDto. { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Delete("Api/colors/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("Api/colors/{@id}", x => new { x.Id }); //endpoint qui supprime une couleur grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct) + public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct) //Méthode asynchrone qui traite la suppression de la couleur { - Models.Color? colorToDelete = await pyrofetesdbcontext - .Colors - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Color? colorToDelete = await pyrofetesdbcontext //Récupère une couleur dans la bdd et le stocke dans colorToDelete + .Colors //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //Recherche une couleur dont l'id correspond à req.Id - if (colorToDelete == null) + if (colorToDelete == null) //Si la couleur n'est pas trouvé { Console.WriteLine($"Aucune couleur 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 } - pyrofetesdbcontext.Colors.Remove(colorToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Colors.Remove(colorToDelete); //Supprime la couleur dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs b/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs index fcfd0e2..c32c362 100644 --- a/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs +++ b/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs @@ -6,21 +6,21 @@ namespace PyroFetes.Endpoints.Color; public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("Api/colors"); - AllowAnonymous(); + Get("Api/colors"); //Endpoint qui affiche toutes les couleurs + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Colors - .Select(a => new GetColorDto + List responseDto = await pyrofetesdbcontext.Colors //Création d'une liste qui récupère toutes les couleurs dans la bdd + .Select(a => new GetColorDto //Sélectionne dans la liste chaque couleur { - Id = a.Id, - Label = a.Label, + Id = a.Id, //Récupère l'id + Label = a.Label, //Récupère le label } - ).ToListAsync(ct); - await Send.OkAsync(responseDto, ct); + ).ToListAsync(ct); //Retourne la liste de couleur + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Color/GetColorEndpoint.cs b/PyroFetes/Endpoints/Color/GetColorEndpoint.cs index bec8c0d..d26a7a6 100644 --- a/PyroFetes/Endpoints/Color/GetColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/GetColorEndpoint.cs @@ -11,31 +11,30 @@ public class GetColorRequest public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() { - Get("Api/colors/{@id}", x => new { x.Id}); - AllowAnonymous(); + Get("Api/colors/{@id}", x => new { x.Id}); //endpoint qui récupère une couleur grâce à son id + AllowAnonymous(); //Autorise l'accès sans authentification } - public override async Task HandleAsync(GetColorRequest req, CancellationToken ct) + public override async Task HandleAsync(GetColorRequest req, CancellationToken ct) //Méthode asynchrone qui traite la récupération de la couleur { - Models.Color? color = await pyrofetesdbcontext - .Colors - .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.Color? color = await pyrofetesdbcontext //Récupère une couleur dans la bdd et le stocke dans color + .Colors //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); //Recherche une couleur dont l'id correspond à req.Id - if (color == null) + if (color == null) //Si la couleur n'est pas trouvé { - Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé."); //Affiche aucune couleur avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - GetColorDto responseDto = new() + GetColorDto responseDto = new() //Constuire l'objet de réponse pour retourner les informations à l'utilisateur { - Id = color.Id, - Label = color.Label, + Id = color.Id, //Affiche l'id lors de la réponse + Label = color.Label, //Affiche le label 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs b/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs index 1cbb3c9..1e434d2 100644 --- a/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs @@ -7,34 +7,34 @@ namespace PyroFetes.Endpoints.Color; public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Put("Api/colors/{@id}", x => new { x.Id }); - AllowAnonymous(); + Put("Api/colors/{@id}", x => new { x.Id }); //Création d'un endpoint qui modifie la couleur grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct) { - Models.Color? colorToEdit = await pyrofetesdbcontext - .Colors - .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.Color? colorToEdit = await pyrofetesdbcontext //Récupère une couleur dans la bdd et le stocke dans colorToEdit + .Colors //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); //Recherche une couleur dont l'id correspond à req.Id - if (colorToEdit == null) + if (colorToEdit == null) //Si la couleur n'est pas trouvé { - Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé."); //Afficher aucune couleur avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - colorToEdit.Label = req.Label; - await pyrofetesdbcontext.SaveChangesAsync(ct); + colorToEdit.Label = req.Label; //Modification du label + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - GetColorDto responseDto = new() + GetColorDto responseDto = new() //Constuire l'objet de réponse pour retourner l'id et le label de la nouvelle couleur { - Id = req.Id, - Label = req.Label, + Id = req.Id, //Affiche l'id + Label = req.Label, //Affiche le label }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } diff --git a/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs index 9596977..ca54128 100644 --- a/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs @@ -4,31 +4,31 @@ using FastEndpoints; namespace PyroFetes.Endpoints.Effect; -public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateEffectDto et l'élement de réponse GetEffectDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("Api/effects"); - AllowAnonymous(); + Post("Api/effects"); //Créer un effet + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct) { - Models.Effect effect = new() + Models.Effect effect = new() //Création d'un label rentré par l'utilisateur { Label = req.Label, }; - pyrofetesdbcontext.Effects.Add(effect); - await pyrofetesdbcontext.SaveChangesAsync(ct); - Console.WriteLine("Effect added"); + pyrofetesdbcontext.Effects.Add(effect); //Ajoute effect à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd + Console.WriteLine("Effect added"); //Affiche Effect added si réussi - GetEffectDto responseDto = new() + GetEffectDto responseDto = new() //Constuire l'objet de réponse pour retourner id et label à l'utilisateur { - Id = effect.Id, - Label = req.Label, + Id = effect.Id, //Affiche l'id lors de la réponse + Label = req.Label, //Affiche le label 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs index f9d4ef6..6a02e8e 100644 --- a/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs @@ -9,28 +9,28 @@ public class DeleteEffectRequest } public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Delete("Api/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("Api/effects/{@id}", x => new { x.Id }); //Création d'un endpoint qui supprime un effet grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct) + public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct) //Méthode asynchrone qui traite la suppression de l'effet { - Models.Effect? effectToDelete = await pyrofetesdbcontext - .Effects - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Effect? effectToDelete = await pyrofetesdbcontext //Récupère un effet dans la bdd et le stocke dans effectToDelete + .Effects //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //Recherche un effet dont l'id correspond à req.Id - if (effectToDelete == null) + if (effectToDelete == null) //Si l'effet n'est pas trouvé { - Console.WriteLine($"Aucun effet avec l'ID {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine($"Aucun effet avec l'ID {req.Id} trouvé."); //Afficher aucun effet avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - pyrofetesdbcontext.Effects.Remove(effectToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Effects.Remove(effectToDelete); //Supprime l'effet dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs b/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs index 753131a..1cbd3d7 100644 --- a/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs @@ -6,22 +6,22 @@ namespace PyroFetes.Endpoints.Effect; public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("Api/effects"); - AllowAnonymous(); + Get("Api/effects"); //Création d'un endpoint pour récupérer tous les effets grâce à la liste + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Effects - .Select(a => new GetEffectDto + List responseDto = await pyrofetesdbcontext.Effects //Création d'une liste qui récupère tous les effets de la bdd + .Select(a => new GetEffectDto //Sélectionne dans la liste chaque effet { - Id = a.Id, - Label = a.Label, + Id = a.Id, //Récupère l'id + Label = a.Label, //Récupère le label } - ).ToListAsync(ct); + ).ToListAsync(ct); //Retourne la liste de effet - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs index 9096551..f541224 100644 --- a/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs @@ -11,31 +11,31 @@ public class GetEffectRequest public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("Api/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); + Get("Api/effects/{@id}", x => new { x.Id }); //Création d'un endpoint qui récupère un effet grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct) + public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct) //Méthode asynchrone qui traite la récupération de l'effet { - Models.Effect? effect = await pyrofetesdbcontext - .Effects - .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.Effect? effect = await pyrofetesdbcontext //Récupère un effet dans la bdd et le stocke dans effect + .Effects //Recherche l'effet dans la table Effects + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); //Recherche un effet dont l'id correspond à req.Id - if (effect == null) + if (effect == null) //Si l'effet n'est pas trouvé { - Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé."); //Afficher aucun effet avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - GetEffectDto responseDto = new() + GetEffectDto responseDto = new() //Constuire l'objet de réponse pour retourner id et label à l'utilisateur { - Id = effect.Id, - Label = effect.Label, + Id = effect.Id, //Affiche l'id lors de la réponse + Label = effect.Label, //Affiche le label 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 + } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs index 468691f..0c29c0b 100644 --- a/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs @@ -7,35 +7,32 @@ namespace PyroFetes.Endpoints.Effect; public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Put("Api/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); + Put("Api/effects/{@id}", x => new { x.Id }); //Création d'un endpoint qui modifie un effet grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct) { - Models.Effect? effectToEdit = await pyrofetesdbcontext - .Effects - .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.Effect? effectToEdit = await pyrofetesdbcontext //Récupère un effet dans la bdd et le stocke dans effectToEdit + .Effects //Recherche l'effet dans la table Effects + .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); //Recherche un effet dont l'id correspond à req.Id - if (effectToEdit == null) + if (effectToEdit == null) //Si l'effet n'est pas trouvé { - Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; - + Console.WriteLine($"Aucun effet avec l'id {req.Id} trouvé."); //Afficher qu'aucun effet avec l'id ... n'a été trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - effectToEdit.Label = req.Label; - await pyrofetesdbcontext.SaveChangesAsync(ct); + effectToEdit.Label = req.Label; //Modification du label de l'effet + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la base de données - GetEffectDto responseDto = new() + GetEffectDto responseDto = new() //Construire l'objet de réponse pour retourner l'id et le label de l'effet modifié { - Id = req.Id, - Label = req.Label, + Id = req.Id, //Inclut l'id dans la réponse + Label = req.Label, //Inclut le label dans la réponse }; - await Send.OkAsync(responseDto, ct); - + await Send.OkAsync(responseDto, ct); //Envoie une réponse 200 OK avec l'objet de réponse } - } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs b/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs index 6fefac4..4842a93 100644 --- a/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs +++ b/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs @@ -5,19 +5,19 @@ using PasswordGenerator; namespace PyroFetes.Endpoints.Login; using FastEndpoints; -public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateLoginDto et l'élement de réponse GetLoginDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/logins"); - AllowAnonymous(); + Post("/api/logins"); //Créer un login + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateLoginDto req, CancellationToken ct) { string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next(); - var login = new Models.Login() + var login = new Models.Login() //Création d'un nom, prénom, mot de passe et un salt rentré par l'utilisateur { Username = req.Username, FullName = req.FullName, @@ -25,12 +25,12 @@ public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateMaterialDto et l'élement de réponse GetMaterialDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("Api/materials"); - AllowAnonymous(); + Post("Api/materials"); //Créer un matériel + AllowAnonymous();//Autorise l'accès sans authentification } public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct) { - Models.Material quantity = new() + Models.Material quantity = new() //Création d'un nom, quantité et liaison de l'id de l'entrepôt rentré par l'utilisateur { Name = req.Label, Quantity = req.Quantity, WarehouseId = req.WarehouseId, }; - pyrofetesdbcontext.Materials.Add(quantity); - await pyrofetesdbcontext.SaveChangesAsync(ct); - Console.WriteLine("Material added"); + pyrofetesdbcontext.Materials.Add(quantity); //Ajoute quantity à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd + Console.WriteLine("Material added"); //Affiche Material Added si réussi - GetMaterialDto responseDto = new() + GetMaterialDto responseDto = new() //Constuire l'objet de réponse pour retourner name, quantity et warehouseId à l'utilisateur { - Id = quantity.Id, - WarehouseId = quantity.WarehouseId, - Label = req.Label, + Id = quantity.Id, //Affiche l'id lors de la réponse + WarehouseId = quantity.WarehouseId, //Affiche le label lors de la réponse + Label = req.Label, //Affiche le label 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs index 6fbdd46..8399c6f 100644 --- a/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs @@ -2,34 +2,34 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Material; -public class DeleteMaterialRequest +public class DeleteMaterialRequest //Création d'une classe DeleteMaterialRequest { - public int Id { get; set; } + public int Id { get; set; } //Création d'un Id } public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Delete("/materials/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("Api/materials/{@id}", x => new { x.Id }); //Création d'un endpoint qui supprime un matériel grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct) + public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct) //Méthode asynchrone qui traite la suppression du matériel { - Models.Material? materialToDelete = await pyrofetesdbcontext - .Materials - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Material? materialToDelete = await pyrofetesdbcontext //Récupère un matériel dans la bdd et le stocke dans materialToDelete + .Materials //Recherche la couleur dans la table Colors + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); //Recherche un matériel dont l'id correspond à req.Id - if (materialToDelete == null) + if (materialToDelete == 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 + } - pyrofetesdbcontext.Materials.Remove(materialToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Materials.Remove(materialToDelete); //Supprime le matériel dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs b/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs index 292959a..32eac23 100644 --- a/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs +++ b/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs @@ -6,23 +6,23 @@ namespace PyroFetes.Endpoints.Material; public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("Api/materials"); - AllowAnonymous(); + Get("Api/materials"); //Création d'un endpoint pour récupérer tous les matériaux grâce à la liste + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Materials - .Select(a => new GetMaterialDto + List responseDto = await pyrofetesdbcontext.Materials //Création d'une liste qui récupère tous les matériaux de la bdd + .Select(a => new GetMaterialDto //Sélectionne dans la liste chaque matériel { - Id = a.Id, - Label = a.Name, - Quantity = a.Quantity, - WarehouseId = a.WarehouseId, + Id = a.Id, //Récupère l'id + Label = a.Name, //Récupère le label + Quantity = a.Quantity, //Récupère la quantité + WarehouseId = a.WarehouseId, //Récupère l'id de l'entrepot } - ).ToListAsync(ct); - await Send.OkAsync(responseDto, ct); + ).ToListAsync(ct); //Retourne la liste du matériel + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs index 2745451..a91f7c1 100644 --- a/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs @@ -11,32 +11,32 @@ public class GetMaterialRequest public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs index 7260213..e1df73a 100644 --- a/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs @@ -7,36 +7,36 @@ namespace PyroFetes.Endpoints.Material; public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Put("Api/materials/{@id}", x => new { x.Id }); - AllowAnonymous(); + Put("Api/materials/{@id}", x => new { x.Id }); //Création d'un endpoint qui modifie le matériel grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct) { - Models.Material? materialToEdit = await pyrofetesdbcontext - .Materials - .SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct); + Models.Material? materialToEdit = await pyrofetesdbcontext //Récupère un matériel dans la bdd et le stocke dans materialToEdit + .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 (materialToEdit == null) + if (materialToEdit == 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 } - materialToEdit.Name = req.Label; - materialToEdit.WarehouseId = req.WarehouseId; - await pyrofetesdbcontext.SaveChangesAsync(ct); + materialToEdit.Name = req.Label; //Modification du label + materialToEdit.WarehouseId = req.WarehouseId; //Modification de warehouseId + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - GetMaterialDto responseDto = new() + GetMaterialDto responseDto = new() //Constuire l'objet de réponse pour retourner l'id, le label et warehouseId du nouveau matériel { - Id = req.Id, - Label = req.Label, - WarehouseId = req.WarehouseId, + Id = req.Id, //Affiche l'id + Label = req.Label, //Affiche le label + WarehouseId = req.WarehouseId, //Affiche warehouseId }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs index d8e838f..2979767 100644 --- a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs @@ -4,18 +4,18 @@ using FastEndpoints; namespace PyroFetes.Endpoints.Movement; -public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint +public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateMovementDto et l'élement de réponse GetMovementDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/movements"); - AllowAnonymous(); + Post("/api/movements"); //Créer un mouvement + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct) { - Models.Movement movement = new () + Models.Movement movement = new () //Création d'une date, d'une date de départ, d'arrivée et d'une quantité rentré par l'utilisateur { Date = req.Date, Start = req.Start, @@ -23,19 +23,19 @@ public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End Quantity = req.Quantity }; - pyrofetesdbcontext.Movements.Add(movement); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Movements.Add(movement); //Ajoute movement à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - Console.WriteLine("Movement créée avec succès !"); + Console.WriteLine("Movement créée avec succès !"); //Affiche Movement créée avec succès ! si réussi - GetMovementDto responseDto = new () + GetMovementDto responseDto = new () //Constuire l'objet de réponse pour retourner les informations à l'utilisateur { - Date = req.Date, - Start = req.Start, - Arrival = req.Arrival, - Quantity = req.Quantity + Date = req.Date, //Affiche date lors de la réponse + Start = req.Start, //Affiche start lors de la réponse + Arrival = req.Arrival, //Affiche arrival lors de la réponse + Quantity = req.Quantity //Affiche quantity 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs index c49bd04..d0bcf10 100644 --- a/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs @@ -3,36 +3,36 @@ using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.Movement; -public class DeleteMovementRequest +public class DeleteMovementRequest //Création d'une classe DeleteMovementRequest { - public int Id { get; set; } + public int Id { get; set; } //Création d'un Id } public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Delete("/api/Movements/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/Movements/{@id}", x => new { x.Id }); //Création d'un endpoint qui supprime un mouvement grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct) + public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct) //Méthode asynchrone qui traite la suppression du mouvement { - Models.Movement? movementToDelete = await pyrofetesdbcontext - .Movements - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Movement? movementToDelete = await pyrofetesdbcontext //Récupère un mouvement dans la bdd et le stocke dans movementToDelete + .Movements //Recherche le mouvement dans la table Movements + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);//Recherche une mouvement dont l'id correspond à req.Id - if (movementToDelete == null) + if (movementToDelete == null) //Si le mouvement n'est pas trouvé { - Console.WriteLine($"Aucune mouvement avec l'ID {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine($"Aucune mouvement avec l'ID {req.Id} trouvé."); //Affiche aucun mouvement avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - pyrofetesdbcontext.Movements.Remove(movementToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Movements.Remove(movementToDelete); //Supprime le mouvement dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs b/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs index da0d977..4be109b 100644 --- a/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs @@ -6,26 +6,26 @@ namespace PyroFetes.Endpoints.Movement; public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("/api/movements"); - AllowAnonymous(); + Get("/api/movements"); //Création d'un endpoint pour récupérer tous les mouvements grâce à la liste + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.Movements - .Select(a => new GetMovementDto + List responseDto = await pyrofetesdbcontext.Movements //Création d'une liste qui récupère tous les mouvements de la bdd + .Select(a => new GetMovementDto //Sélectionne dans la liste chaque mouvement { - Id = a.Id, - Date = a.Date, - Start = a.Start, - Arrival = a.Arrival, - Quantity = a.Quantity + Id = a.Id, //Récupère l'id + Date = a.Date, //Récupère la date + Start = a.Start, //Récupère start + Arrival = a.Arrival, //Récupère arrival + Quantity = a.Quantity //Récupère quantity } - ).ToListAsync(ct); + ).ToListAsync(ct); //Retourne la liste de mouvement - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs index 33e60ec..4f16a52 100644 --- a/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs @@ -11,35 +11,35 @@ public class GetMovementRequest public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Get("/api/movements/{@id}", x => new { x.Id }); - AllowAnonymous(); + Get("/api/movements/{@id}", x => new { x.Id }); //Création d'un endpoint qui récupère un mouvement grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } - public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct) + public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct) //Méthode asynchrone qui traite la récupération du mouvement { - Models.Movement? movement = await pyrofetesdbcontext - .Movements - .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct); + Models.Movement? movement = await pyrofetesdbcontext //Récupère un mouvement dans la bdd et le stocke dans movement + .Movements //Recherche la couleur dans la table Movements + .SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);//Recherche un mouvement dont l'id correspond à req.Id - if (movement == null) + if (movement == null) //Si le mouvement n'est pas trouvé { - Console.WriteLine($"Aucun mouvement avec l'ID {req.Id} trouvé."); - await Send.NotFoundAsync(ct); - return; + Console.WriteLine($"Aucun mouvement avec l'ID {req.Id} trouvé."); //Affiche aucun mouvement avec l'id ... trouvé + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - GetMovementDto responseDto = new() + GetMovementDto responseDto = new() //Constuire l'objet de réponse pour retourner les informations à l'utilisateur { - Id = req.Id, - Date = movement.Date, - Start = movement.Start, - Arrival = movement.Arrival, - Quantity = movement.Quantity + Id = req.Id, //Affiche l'id lors de la réponse + Date = movement.Date, //Affiche date lors de la réponse + Start = movement.Start, //Affiche start lors de la réponse + Arrival = movement.Arrival, //Affiche arrival lors de la réponse + Quantity = movement.Quantity //Affiche quantity 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 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs index 9e69545..e5195b8 100644 --- a/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs @@ -6,26 +6,26 @@ namespace PyroFetes.Endpoints.Movement; public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Put("/api/movements"); - AllowAnonymous(); + Put("/api/movements"); //Création d'un endpoint qui modifie le mouvement grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct) { - Models.Movement movement = new() + Models.Movement movement = new() { Date = req.Date, Start = req.Start, Arrival = req.Arrival, Quantity = req.Quantity }; - pyrofetesdbcontext.Add(movement); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Add(movement); //Modification du mouvement + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - GetMovementDto response = new() + GetMovementDto response = new() //Constuire l'objet de réponse pour retourner les informations du mouvement { Id = req.Id, Date = req.Date, @@ -34,7 +34,7 @@ public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End Quantity = req.Quantity }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs index d6bc518..2ccafdb 100644 --- a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs @@ -7,17 +7,17 @@ using PyroFetes.Models; namespace PyroFetes.Endpoints.Product; public class CreateProductEndpoint(PyroFetesDbContext db) - : Endpoint + : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateProductDto et l'élement de réponse GetProductDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/products"); - AllowAnonymous(); + Post("/api/products"); //Créer un produit + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateProductDto req, CancellationToken ct) { - var product = new Models.Product + var product = new Models.Product //Création d'un nom, référence, durée, calibre, numéro d'aprovisionnement, poids, nec, image, lien, liaison de la catégorie du produit et de la classification rentré par l'utilisateur { Reference = req.References.ToString(), Name = req.Name!, @@ -32,8 +32,8 @@ public class CreateProductEndpoint(PyroFetesDbContext db) ClassificationId = req.ClassificationId }; - db.Products.Add(product); - await db.SaveChangesAsync(ct); + db.Products.Add(product); //Ajout du produit à la bdd + await db.SaveChangesAsync(ct); //Sauvegarde du produit dans la bdd // Ajout des fournisseurs liés if (req.Suppliers is not null && req.Suppliers.Any()) @@ -46,9 +46,9 @@ public class CreateProductEndpoint(PyroFetesDbContext db) SupplierId = s.SupplierId, SellingPrice = s.SellingPrice }; - db.Prices.Add(price); + db.Prices.Add(price); //Ajout du prix à la bdd } - await db.SaveChangesAsync(ct); + await db.SaveChangesAsync(ct); //Sauvegarde du produit dans la bdd } // Ajout des entrepôts liés @@ -66,9 +66,9 @@ public class CreateProductEndpoint(PyroFetesDbContext db) WarehouseId = w.WarehouseId, Quantity = w.Quantity }; - db.WarehouseProducts.Add(warehouseProduct); + db.WarehouseProducts.Add(warehouseProduct); //Ajout du produit de l'entrepot à la bdd } - await db.SaveChangesAsync(ct); + await db.SaveChangesAsync(ct); //Sauvegarde du produit de l'entrepot dans la bdd } // Construction de la réponse @@ -100,6 +100,6 @@ public class CreateProductEndpoint(PyroFetesDbContext db) }).ToList() ?? new() }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Réponse au client } } diff --git a/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs b/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs index f400abe..15f2629 100644 --- a/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs @@ -6,28 +6,28 @@ namespace PyroFetes.Endpoints.Product; public class DeleteProductRequest { - public int Id { get; set; } + public int Id { get; set; } //Création d'un Id } public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint { public override void Configure() { - Delete("/api/products/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/products/{@id}", x => new { x.Id }); //endpoint qui supprime un produit grâce à son id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct) { // Récupérer le produit - var productToDelete = await db.Products + var productToDelete = await db.Products .SingleOrDefaultAsync(p => p.Id == req.Id, ct); if (productToDelete is null) { Console.WriteLine($"Aucun produit 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 } // Supprimer les liaisons Price @@ -54,6 +54,6 @@ public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint +public class CreateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateProductCategoryDto et l'élement de réponse GetProductCategoryDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/productcategories"); - AllowAnonymous(); + Post("/api/productcategories"); //Créer une catégorie de produits + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateProductCategoryDto req, CancellationToken ct) { - Models.ProductCategory productCategory = new () + Models.ProductCategory productCategory = new () //Création d'un label rentré par l'utilisateur { Label = req.Label, }; - pyrofetesdbcontext.ProductCategories.Add(productCategory); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.ProductCategories.Add(productCategory); //Ajout du catégorie de la produit à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde du catégorie de la produit dans la bdd Console.WriteLine("Category créé avec succès !"); - GetProductCategoryDto responseDto = new () + GetProductCategoryDto responseDto = new () //renvoie l'id et le label { Id = productCategory.Id, Label = productCategory.Label }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Réponse au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs index 9b00562..7fe4ce1 100644 --- a/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs @@ -12,25 +12,25 @@ public class DeleteProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext { public override void Configure() { - Delete("/api/productcategories/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/productcategories/{@id}", x => new { x.Id }); //endpoint qui supprime une catégorie de produit grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(DeleteProductCategoryRequest req, CancellationToken ct) { - Models.ProductCategory? productCategoryToDelete = await pyrofetesdbcontext - .ProductCategories - .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct); + Models.ProductCategory? productCategoryToDelete = await pyrofetesdbcontext //Récupère une catégorie de produit dans la bdd et le stocke dans productCategoryToDelete + .ProductCategories //Recherche la couleur dans la table ProductCategories + .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct); //Recherche une catégorie de produit dont l'id correspond à req.Id if (productCategoryToDelete == null) { - await Send.NotFoundAsync(ct); - return; + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - pyrofetesdbcontext.ProductCategories.Remove(productCategoryToDelete); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.ProductCategories.Remove(productCategoryToDelete); //Supprime la catégorie de produit dans la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs index d0039c6..1068c5c 100644 --- a/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs @@ -8,20 +8,20 @@ public class GetAllProductCategoriesEndpoint(PyroFetesDbContext pyrofetesdbconte { public override void Configure() { - Get("/api/productcategories"); - AllowAnonymous(); + Get("/api/productcategories"); //Endpoint qui affiche toutes les catégories de produits + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(CancellationToken ct) { - List responseDto = await pyrofetesdbcontext.ProductCategories - .Select(pc => new GetProductCategoryDto() + List responseDto = await pyrofetesdbcontext.ProductCategories //Création d'une liste qui récupère toutes les catégories de produits dans la bdd + .Select(pc => new GetProductCategoryDto() //Sélectionne dans la liste chaque catégorie de produits { - Id = pc.Id, - Label = pc.Label + Id = pc.Id, //Récupère l'id + Label = pc.Label //Récupère le label } - ).ToListAsync(ct); + ).ToListAsync(ct); //Retourne la liste - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } diff --git a/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs index f2d823b..de9ff2c 100644 --- a/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs @@ -14,29 +14,29 @@ public class GetProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : { public override void Configure() { - Get("/api/productcategory/{@id}", x => new { x.Id }); - AllowAnonymous(); + Get("/api/productcategory/{@id}", x => new { x.Id }); //endpoint qui récupère une catégorie de produit grâce à son id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(GetProductCategoryRequest req, CancellationToken ct) { - Models.ProductCategory? productCategory = await pyrofetesdbcontext - .ProductCategories - .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct); + Models.ProductCategory? productCategory = await pyrofetesdbcontext //Récupère une catégorie de produits dans la bdd et le stocke dans productCategory + .ProductCategories //Recherche dans la table ProductCategories + .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct);//Recherche une catégorie de produits dont l'id correspond à req.Id - if (productCategory == null) + if (productCategory == null) //Si la catégorie de produit n'est pas trouvé { - await Send.NotFoundAsync(ct); - return; + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } GetProductCategoryDto responseDto = new() { - Id = productCategory.Id, - Label = productCategory.Label + Id = productCategory.Id, //Affiche l'id lors de la réponse + Label = productCategory.Label //Affiche le label 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 } } diff --git a/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs index e5d7e21..dbe894c 100644 --- a/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs @@ -9,31 +9,31 @@ public class UpdateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext { public override void Configure() { - Put("/api/productcategory/{@id}", x => new { x.Id }); - AllowAnonymous(); + Put("/api/productcategory/{@id}", x => new { x.Id }); //endpoint qui modifie la catégorie de produit grâce à son id + AllowAnonymous(); //Ignorer les requêtes non authentifiées } public override async Task HandleAsync(UpdateProductCategoryDto req, CancellationToken ct) { - Models.ProductCategory? productCategoryToEdit = await pyrofetesdbcontext - .ProductCategories - .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct); + Models.ProductCategory? productCategoryToEdit = await pyrofetesdbcontext //Récupère une catégorie de produits dans la bdd et le stocke dans productCategoryToEdit + .ProductCategories //Recherche dans la table ProductCategories + .SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct); //Recherche une catégorie de produits dont l'id correspond à req.Id - if (productCategoryToEdit == null) + if (productCategoryToEdit == null) //Si la catégorie de produit n'est pas trouvé { - await Send.NotFoundAsync(ct); - return; + await Send.NotFoundAsync(ct); //Renvoie une erreur 404 + return; //Arrêt de la méthode } - productCategoryToEdit.Label = req.Label; - await pyrofetesdbcontext.SaveChangesAsync(ct); + productCategoryToEdit.Label = req.Label; //Modification du label + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements effectués dans la bdd GetProductCategoryDto responseDto = new() { - Id = req.Id, - Label = req.Label, + Id = req.Id, //Affiche l'id + Label = req.Label, //Affiche le label }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(responseDto, ct); //Envoie de la réponse réussite 200 au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs index 530e1af..3703874 100644 --- a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs @@ -7,17 +7,17 @@ using PyroFetes.Models; namespace PyroFetes.Endpoints.Supplier; public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) - : Endpoint + : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateSupplierDto et l'élement de réponse GetSupplierDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/suppliers"); - AllowAnonymous(); + Post("/api/suppliers"); //Créer un fournisseur + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) { - var supplier = new Models.Supplier + var supplier = new Models.Supplier //Création d'un nom, email, numéro de téléphone, adresse, code postal et nom de la ville rentré par l'utilisateur { Name = req.Name, Email = req.Email, @@ -27,8 +27,8 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) City = req.City }; - pyrofetesdbcontext.Suppliers.Add(supplier); - await pyrofetesdbcontext.SaveChangesAsync(ct); + pyrofetesdbcontext.Suppliers.Add(supplier); //Ajout du fournisseur à la bdd + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde du fournisseur dans la bdd // Ajout des liaisons Price si produits renseignés if (req.Products is not null && req.Products.Any()) @@ -43,10 +43,10 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) }; pyrofetesdbcontext.Prices.Add(price); } - await pyrofetesdbcontext.SaveChangesAsync(ct); + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde du fournisseur dans la bdd } - var response = new GetSupplierDto + var response = new GetSupplierDto //renvoie l'id, d'un nom, d'un email, d'un numéro de téléphone, d'une adresse, d'un code postal et du nom de la ville { Id = supplier.Id, Name = supplier.Name, @@ -57,6 +57,6 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) City = supplier.City }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Réponse au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs index e9735dc..52ec762 100644 --- a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs @@ -13,21 +13,21 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End { public override void Configure() { - Delete("/api/suppliers/{@id}", x => new { x.Id }); - AllowAnonymous(); + Delete("/api/suppliers/{@id}", x => new { x.Id }); //Endpoint qui supprime un fournisseur en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct) { - var supplierToDelete = await pyrofetesdbcontext - .Suppliers - .SingleOrDefaultAsync(s => s.Id == req.Id, ct); + var supplierToDelete = await pyrofetesdbcontext //Récupère un fournisseur dans la bdd et le stocke dans supplierToDelete + .Suppliers //Recherche un fournisseur dans la table Suppliers + .SingleOrDefaultAsync(s => s.Id == req.Id, ct); //Recherche un fournisseur dont l'id correspond à req.Id if (supplierToDelete is null) { Console.WriteLine($"Aucun fournisseur 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 } // Supprimer les liaisons Price avant le fournisseur @@ -46,6 +46,6 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End await pyrofetesdbcontext.SaveChangesAsync(ct); Console.WriteLine($"Fournisseur {req.Id} et ses prix liés supprimés avec succès."); - await Send.NoContentAsync(ct); + await Send.NoContentAsync(ct); //Renvoie une réponse réussite 204 } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs index 28517a3..296b505 100644 --- a/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs @@ -11,8 +11,8 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) { public override void Configure() { - Get("/api/suppliers"); - AllowAnonymous(); + Get("/api/suppliers"); //endpoint qui affiche le fournisseur en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs index a66bfad..ed28f97 100644 --- a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs @@ -15,8 +15,8 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) { public override void Configure() { - Get("/api/suppliers/{@id}", x => new { x.Id }); - AllowAnonymous(); + Get("/api/suppliers/{@id}", x => new { x.Id }); //endpoint qui affiche le fournisseur en fonction de l'id + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) @@ -28,8 +28,8 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) if (supplier == null) { Console.WriteLine($"Aucun fournisseur 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 } var responseDto = new GetSupplierDto diff --git a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs index fde3c2e..422651e 100644 --- a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs @@ -52,7 +52,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End } } - await pyrofetesdbcontext.SaveChangesAsync(ct); + await pyrofetesdbcontext.SaveChangesAsync(ct); //Sauvegarde les changements var response = new GetSupplierDto { @@ -65,6 +65,6 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End City = supplierToEdit.City }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Envoie de la réponse réussite 200 au client } } diff --git a/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs b/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs index e6ff638..2067876 100644 --- a/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs +++ b/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs @@ -6,17 +6,17 @@ using PyroFetes.Models; namespace PyroFetes.Endpoints.Warehouse; public class CreateWarehouseEndpoint(PyroFetesDbContext db) - : Endpoint + : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateWarehouseDto et l'élement de réponse GetWarehouseDto { - public override void Configure() + public override void Configure() //Configuration de l'endpoint { - Post("/api/warehouse"); - AllowAnonymous(); + Post("/api/warehouse"); //Créer un entrepot + AllowAnonymous(); //Autorise l'accès sans authentification } public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct) { - var warehouse = new Models.Warehouse + var warehouse = new Models.Warehouse //Création d'un nom, d'un poids maximal et minimal, d'une adresse, d'un code postal et du nom de la ville rentré par l'utilisateur { Name = req.Name, MaxWeight = req.MaxWeight, @@ -27,8 +27,8 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext db) City = req.City }; - db.Warehouses.Add(warehouse); - await db.SaveChangesAsync(ct); + db.Warehouses.Add(warehouse); //Ajout de l'entrepot à la bdd + await db.SaveChangesAsync(ct); //Sauvegarde de l'entrepot dans la bdd // 🔹 Ajout des produits liés à cet entrepôt if (req.Products is not null && req.Products.Any()) @@ -46,7 +46,7 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext db) await db.SaveChangesAsync(ct); } - var response = new GetWarehouseDto + var response = new GetWarehouseDto //renvoie l'id, d'un nom, d'un poids maximal et minimal, d'une adresse, d'un code postal et du nom de la ville { Id = warehouse.Id, Name = warehouse.Name, @@ -58,6 +58,6 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext db) City = warehouse.City }; - await Send.OkAsync(response, ct); + await Send.OkAsync(response, ct); //Réponse au client } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs b/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs index 4ea299d..b141457 100644 --- a/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs +++ b/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs @@ -45,6 +45,6 @@ public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint