diff --git a/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs index a3147be..ec14d88 100644 --- a/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/CreateBrandEndpoint.cs @@ -9,7 +9,6 @@ public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Post("/brands"); - AllowAnonymous(); } public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs index c32821d..e0a6f4e 100644 --- a/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/DeleteBrandEndpoint.cs @@ -13,7 +13,6 @@ public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Delete("/brands/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs b/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs index 210e13c..206195b 100644 --- a/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/GetAllBrandsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo public override void Configure() { Get("/brands"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs index 56e5256..9f11428 100644 --- a/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/GetBrandEndpoint.cs @@ -14,7 +14,6 @@ public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs b/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs index f5aa408..4067ed4 100644 --- a/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs +++ b/PyroFetes/Endpoints/Brand/UpdateBrandEndpoint.cs @@ -9,7 +9,6 @@ public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Put("/brands/{Id}"); - AllowAnonymous(); } public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs index 8690b95..32db144 100644 --- a/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/CreateClassificationEndpoint.cs @@ -9,7 +9,6 @@ public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) public override void Configure() { Post("/classifications"); - AllowAnonymous(); } public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs index 969677f..41acdb6 100644 --- a/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/DeleteClassificationEndpoint.cs @@ -13,7 +13,6 @@ public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) : public override void Configure() { Delete("/classifications/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs b/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs index 5c5686d..d19c6d6 100644 --- a/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/GetAllClassificationsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext public override void Configure() { Get("/classifications"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs index e709089..39d8855 100644 --- a/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/GetClassificationEndpoint.cs @@ -14,7 +14,6 @@ public class GetClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) :E public override void Configure() { Get("/classifications/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetClassificationRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs b/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs index 1dd9bc7..f5c5e3c 100644 --- a/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs +++ b/PyroFetes/Endpoints/Classification/UpdateClassificationEndpoint.cs @@ -9,7 +9,6 @@ public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) public override void Configure() { Put("/classifications"); - AllowAnonymous(); } public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs b/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs index 206f905..cb5880a 100644 --- a/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/CreateColorEndpoint.cs @@ -1,16 +1,14 @@ using API.DTO.Color.Request; using API.DTO.Color.Response; using FastEndpoints; -using PyroFetes; -namespace API.Endpoints.Color; +namespace PyroFetes.Endpoints.Color; public class CreateColorEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateColorDto et l'élement de réponse GetColorDto { public override void Configure() //Configuration de l'endpoint { Post("/colors"); //Création d'un endpoint pour créer une couleur avec les données de CreateColorDto - AllowAnonymous(); //Laisser passer les requêtes non authentifiées } 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 diff --git a/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs b/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs index 51c2505..c3d2c4d 100644 --- a/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/DeleteColorEndpoint.cs @@ -13,7 +13,6 @@ public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Delete("/colors/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs b/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs index a2f9b39..be75b77 100644 --- a/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs +++ b/PyroFetes/Endpoints/Color/GetAllColorsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo public override void Configure() { Get("/colors"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Color/GetColorEndpoint.cs b/PyroFetes/Endpoints/Color/GetColorEndpoint.cs index dcacb8a..3600f28 100644 --- a/PyroFetes/Endpoints/Color/GetColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/GetColorEndpoint.cs @@ -14,7 +14,6 @@ public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint< public override void Configure() { Get("/colors/{@id}", x => new { x.Id}); - AllowAnonymous(); } public override async Task HandleAsync(GetColorRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs b/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs index b05c896..8c5ccf2 100644 --- a/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs +++ b/PyroFetes/Endpoints/Color/UpdateColorEndpoint.cs @@ -10,7 +10,6 @@ public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Put("/colors/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs index c974f7f..44bcc9f 100644 --- a/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/CreateEffectEndpoint.cs @@ -9,7 +9,6 @@ public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo public override void Configure() { Post("/effects"); - AllowAnonymous(); } public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs index 98549dc..12fecb6 100644 --- a/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/DeleteEffectEndpoint.cs @@ -12,7 +12,6 @@ public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo public override void Configure() { Delete("/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs b/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs index fd1c903..894d6f8 100644 --- a/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/GetAllEffectsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp public override void Configure() { Get("/effects"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs index 115dbbb..29c4f47 100644 --- a/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/GetEffectEndpoint.cs @@ -14,7 +14,6 @@ public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint public override void Configure() { Get("/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs index 085d589..777d12e 100644 --- a/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs +++ b/PyroFetes/Endpoints/Effect/UpdateEffectEndpoint.cs @@ -10,8 +10,7 @@ public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo public override void Configure() { Put("/effects/{@id}", x => new { x.Id }); - AllowAnonymous(); - } + } public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct) { diff --git a/PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs index ac13f33..ca9df99 100644 --- a/PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/CreateMaterialEndpoint.cs @@ -9,7 +9,6 @@ public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Post("/materials"); - AllowAnonymous(); } public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs index 6fbdd46..6b39092 100644 --- a/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/DeleteMaterialEndpoint.cs @@ -11,7 +11,6 @@ public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Delete("/materials/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs b/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs index e4268e9..a75a6d9 100644 --- a/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs +++ b/PyroFetes/Endpoints/Material/GetAllMaterialsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En public override void Configure() { Get("/materials"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs index 57b5b62..5882341 100644 --- a/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/GetMaterialEndpoint.cs @@ -14,7 +14,6 @@ public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi public override void Configure() { Get("/materials/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs b/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs index 8468374..9c5cfff 100644 --- a/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs +++ b/PyroFetes/Endpoints/Material/UpdateMaterialEndpoint.cs @@ -10,7 +10,6 @@ public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Put("/materials/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs index 069462d..ee4cbb3 100644 --- a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs @@ -9,7 +9,6 @@ public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Post("/movements"); - AllowAnonymous(); } public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs index d112cd5..42ec4ae 100644 --- a/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/DeleteMovementEndpoint.cs @@ -13,7 +13,6 @@ public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Delete("/Movements/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs b/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs index 68655a8..5754054 100644 --- a/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/GetAllMovementsEndpoint.cs @@ -9,7 +9,6 @@ public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En public override void Configure() { Get("/movements"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs index f496265..8e58620 100644 --- a/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/GetMovementEndpoint.cs @@ -14,7 +14,6 @@ public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoin public override void Configure() { Get("/movements/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs index dd6d859..f4fc9bc 100644 --- a/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/UpdateMovementEndpoint.cs @@ -9,7 +9,6 @@ public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Put("/movements"); - AllowAnonymous(); } public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs index ffc0c25..eb07c73 100644 --- a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs @@ -12,7 +12,6 @@ public class CreateProductEndpoint(PyroFetesDbContext db) public override void Configure() { Post("/products"); - AllowAnonymous(); } public override async Task HandleAsync(CreateProductDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs b/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs index 57bed29..fdb96ca 100644 --- a/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/DeleteProductEndpoint.cs @@ -14,7 +14,6 @@ public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs index 9447210..c755faf 100644 --- a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs +++ b/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs @@ -12,7 +12,6 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db) public override void Configure() { Get("/products"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs b/PyroFetes/Endpoints/Product/GetProductEndpoint.cs index 279086a..42c489b 100644 --- a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/GetProductEndpoint.cs @@ -17,7 +17,6 @@ public class GetProductEndpoint(PyroFetesDbContext db) public override void Configure() { Get("/products/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetProductRequest req, CancellationToken ct) @@ -25,7 +24,7 @@ public class GetProductEndpoint(PyroFetesDbContext db) // Inclure toutes les relations : Prices + WarehouseProducts + Warehouse var product = await db.Products .Include(p => p.Prices) - .Include(p => p.WarehouseProducts) + .Include(p => p.WarehouseProducts)! .ThenInclude(wp => wp.Warehouse) .SingleOrDefaultAsync(p => p.Id == req.Id, ct); diff --git a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs index 6adecff..8c8f6bf 100644 --- a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs @@ -6,36 +6,29 @@ using PyroFetes.Models; namespace PyroFetes.Endpoints.Product; -// Endpoint permettant de mettre à jour un produit existant public class UpdateProductEndpoint(PyroFetesDbContext db) : Endpoint { public override void Configure() { - // Route HTTP PUT avec un paramètre d'identifiant dans l'URL Put("/products/{@id}", x => new { x.Id }); - // Autorise les requêtes anonymes (sans authentification) - AllowAnonymous(); } public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct) { - // Recherche du produit à mettre à jour, en incluant les relations Prices et WarehouseProducts var product = await db.Products .Include(p => p.Prices) .Include(p => p.WarehouseProducts) .SingleOrDefaultAsync(p => p.Id == req.Id, ct); - // Si le produit n'existe pas, on retourne une réponse 404 if (product is null) { await Send.NotFoundAsync(ct); return; } - // Mise à jour des propriétés principales du produit - product.Reference = req.Reference; // Converti int → string + product.Reference = req.Reference; product.Name = req.Name; product.Duration = req.Duration; product.Caliber = req.Caliber; @@ -47,7 +40,6 @@ public class UpdateProductEndpoint(PyroFetesDbContext db) product.ClassificationId = req.ClassificationId; product.ProductCategoryId = req.ProductCategoryId; - // Mise à jour des prix fournisseurs associés db.Prices.RemoveRange(product.Prices); foreach (var s in req.Suppliers) { @@ -59,7 +51,6 @@ public class UpdateProductEndpoint(PyroFetesDbContext db) }); } - // Mise à jour des entrepôts associés db.WarehouseProducts.RemoveRange(product.WarehouseProducts); foreach (var w in req.Warehouses) { @@ -73,18 +64,16 @@ public class UpdateProductEndpoint(PyroFetesDbContext db) await db.SaveChangesAsync(ct); - // Construction de la réponse renvoyée au client var response = new GetProductDto { Id = product.Id, - Reference = req.Reference, // DTO garde int pour cohérence + Reference = req.Reference, Name = req.Name, Duration = req.Duration, Caliber = req.Caliber, ApprovalNumber = req.ApprovalNumber, Weight = req.Weight, Nec = req.Nec, - // Le prix de vente est pris depuis Prices SellingPrice = req.Suppliers.FirstOrDefault()?.SellingPrice ?? 0, Image = req.Image, Link = req.Link, diff --git a/PyroFetes/Endpoints/ProductCategory/CreateProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/CreateProductCategoryEndpoint.cs index e991ac3..a9441ac 100644 --- a/PyroFetes/Endpoints/ProductCategory/CreateProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/CreateProductCategoryEndpoint.cs @@ -9,7 +9,6 @@ public class CreateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext public override void Configure() { Post("/productcategories"); - AllowAnonymous(); } public override async Task HandleAsync(CreateProductCategoryDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs index ef563b6..1e2e620 100644 --- a/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/DeleteProductCategoryEndpoint.cs @@ -13,7 +13,6 @@ public class DeleteProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext public override void Configure() { Delete("/productcategories/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteProductCategoryRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoryEndpoint.cs similarity index 79% rename from PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs rename to PyroFetes/Endpoints/ProductCategory/GetAllProductCategoryEndpoint.cs index 3a9a0f2..5e6b274 100644 --- a/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoriesEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/GetAllProductCategoryEndpoint.cs @@ -4,12 +4,11 @@ using Microsoft.EntityFrameworkCore; namespace PyroFetes.Endpoints.ProductCategory; -public class GetAllProductCategoriesEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> +public class GetAllProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest> { public override void Configure() { Get("/productcategories"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs index d9a39ee..8f16129 100644 --- a/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/GetProductCategoryEndpoint.cs @@ -15,7 +15,6 @@ public class GetProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : public override void Configure() { Get("/productcategory/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetProductCategoryRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs b/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs index e5987f6..acaf2b3 100644 --- a/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs +++ b/PyroFetes/Endpoints/ProductCategory/UpdateProductCategoryEndpoint.cs @@ -10,7 +10,6 @@ public class UpdateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext public override void Configure() { Put("/productcategory/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(UpdateProductCategoryDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs index f0be16c..d5b09a7 100644 --- a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs @@ -12,7 +12,6 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) public override void Configure() { Post("/suppliers"); - AllowAnonymous(); } public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs index f63d3d2..404f5ff 100644 --- a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs @@ -14,7 +14,6 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Delete("/suppliers/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs index 8f019ff..bd486df 100644 --- a/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/GetAllSupplierEndpoint.cs @@ -12,7 +12,6 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) public override void Configure() { Get("/suppliers"); - AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs index 74fd30f..5e85028 100644 --- a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs @@ -16,7 +16,6 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) public override void Configure() { Get("/suppliers/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs index a3938fe..89fce93 100644 --- a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs @@ -11,7 +11,6 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End public override void Configure() { Put("/suppliers/{@id}", x => new { x.Id }); - AllowAnonymous(); } public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs b/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs index ac8a12d..b9c33eb 100644 --- a/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs +++ b/PyroFetes/Endpoints/Warehouse/CreateWarehouseEndpoint.cs @@ -11,7 +11,6 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext db) public override void Configure() { Post("/warehouse"); - AllowAnonymous(); } public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs b/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs index 994fc64..831c75c 100644 --- a/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs +++ b/PyroFetes/Endpoints/Warehouse/DeleteWarehouseEndpoint.cs @@ -14,7 +14,6 @@ public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") + .AddAuthentication(); + +builder.Services.AddAuthorization(); + builder.Services.AddCors(options => options.AddDefaultPolicy(policyBuilder => - policyBuilder - .WithOrigins("http://localhost:4200") // mettre le port Angular exact - .WithMethods("GET", "POST", "PUT", "PATCH", "DELETE") - .AllowAnyHeader() + policyBuilder.WithOrigins("http://localhost:4200") + .WithMethods("GET", "POST", "PUT", "PATCH", "DELETE") + .AllowAnyHeader() + .AllowCredentials() ) ); -builder.Services.AddFastEndpoints().SwaggerDocument(options => +builder.Services.AddFastEndpoints().SwaggerDocument(options => { options.ShortSchemaNames = true; }); @@ -23,20 +30,19 @@ builder.Services.AddDbContext(); WebApplication app = builder.Build(); -// Middleware + app.UseHttpsRedirection(); -// CORS doit être avant les endpoints app.UseCors(); -// FastEndpoints et Swagger +app.UseAuthentication(); + +app.UseAuthorization(); + app.UseFastEndpoints(options => { - options.Endpoints.RoutePrefix = "API"; + options.Endpoints.RoutePrefix = "API"; options.Endpoints.ShortNames = true; }).UseSwaggerGen(); -// app.UseAuthorization(); -// app.UseAuthentication(); - app.Run(); \ No newline at end of file