From 74b5fa6666a918b48e6c4d76962f8c81f3c49ea2 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 17:24:36 +0200 Subject: [PATCH 1/6] editing dto from PurchaseProduct --- .../Request/CreatePurchaseProductDto.cs | 13 ----- .../Response/GetPurchaseProductDto.cs | 6 +-- .../CreatePurchaseProductEndpoint.cs | 52 +++++++++++++++++++ .../DeletePurchaseProductEndpoint.cs | 6 +++ .../GetAllPurchasesProductsEndpoint.cs | 6 +++ .../GetPurchaseProductEndpoint.cs | 6 +++ .../PatchPurchaseProductQuantityEndpoint.cs | 6 +++ .../UpdatePurchaseProductEndpoint.cs | 6 +++ PyroFetes/PyroFetes.csproj | 2 + 9 files changed, 86 insertions(+), 17 deletions(-) create mode 100644 PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs create mode 100644 PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs create mode 100644 PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs create mode 100644 PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs create mode 100644 PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs create mode 100644 PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs diff --git a/PyroFetes/DTO/PurchaseProduct/Request/CreatePurchaseProductDto.cs b/PyroFetes/DTO/PurchaseProduct/Request/CreatePurchaseProductDto.cs index bac3997..1249b41 100644 --- a/PyroFetes/DTO/PurchaseProduct/Request/CreatePurchaseProductDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Request/CreatePurchaseProductDto.cs @@ -3,20 +3,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request; public class CreatePurchaseProductDto { public int Quantity { get; set; } - public int ProductId { get; set; } - public int ProductReferences { get; set; } - public string? ProductName { get; set; } - public decimal ProductDuration {get; set;} - public decimal ProductCaliber { get; set; } - public int ProductApprovalNumber { get; set; } - public decimal ProductWeight { get; set; } - public decimal ProductNec { get; set; } - public string? ProductImage { get; set; } - public string? ProductLink { get; set; } - public int ProductMinimalQuantity { get; set; } - - public int PurchaseOrderId { get; set; } public string? PurchaseOrderPurchaseConditions { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs index 1858e3f..a4d5234 100644 --- a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs @@ -2,9 +2,6 @@ namespace PyroFetes.DTO.PurchaseProduct.Response; public class GetPurchaseProductDto { - public int Id { get; set; } - public int Quantity { get; set; } - public int ProductId { get; set; } public int ProductReferences { get; set; } public string? ProductName { get; set; } @@ -18,7 +15,8 @@ public class GetPurchaseProductDto public string? ProductLink { get; set; } public int ProductMinimalQuantity { get; set; } - public int PurchaseOrderId { get; set; } public string? PurchaseOrderPurchaseConditions { get; set; } + + public int Quantity { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs new file mode 100644 index 0000000..56ab3a9 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs @@ -0,0 +1,52 @@ +using Microsoft.EntityFrameworkCore; +using FastEndpoints; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.DTO.PurchaseProduct.Response; + +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Post("/api/purchaseProducts"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) + { + var purchaseOrderExists = await database.PurchaseOrders.FirstOrDefaultAsync(a => a.Id == req.PurchaseOrderId, ct); + + if (purchaseOrderExists == null) + { + await Send.NoContentAsync(ct); + return; + } + + var purchaseProduct = new Models.PurchaseProduct() + { + ProductId = req.ProductId, + PurchaseOrderId = req.PurchaseOrderId, + Quantity = req.Quantity + }; + database.PurchaseProducts.Add(purchaseProduct); + + var purchaseOrder = new Models.PurchaseOrder() + { + PurchaseConditions = req.PurchaseOrderPurchaseConditions, + }; + database.PurchaseOrders.Add(purchaseOrder); + + await database.SaveChangesAsync(ct); + + GetPurchaseProductDto responseDto = new() + { + ProductId = purchaseProduct.ProductId, + PurchaseOrderId = purchaseProduct.PurchaseOrderId, + Quantity = purchaseProduct.Quantity, + PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions, + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs new file mode 100644 index 0000000..1f532ff --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class DeletePurchaseProductEndpoint +{ + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs new file mode 100644 index 0000000..54517ff --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class GetAllPurchasesProductsEndpoint +{ + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs new file mode 100644 index 0000000..9527e4c --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class GetPurchaseProductEndpoint +{ + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs new file mode 100644 index 0000000..7772a82 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class PatchPurchaseProductQuantityEndpoint +{ + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs new file mode 100644 index 0000000..3373ae9 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs @@ -0,0 +1,6 @@ +namespace PyroFetes.Endpoints.PurchaseProduct; + +public class UpdatePurchaseProductEndpoint +{ + +} \ No newline at end of file diff --git a/PyroFetes/PyroFetes.csproj b/PyroFetes/PyroFetes.csproj index 60e4770..289fb53 100644 --- a/PyroFetes/PyroFetes.csproj +++ b/PyroFetes/PyroFetes.csproj @@ -7,6 +7,8 @@ + + From 31e69aae1a158ad3908f002fd1b01eef1807f4ac Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 17:53:16 +0200 Subject: [PATCH 2/6] Creating purchaseproduct's endpoint --- .../Response/GetPurchaseProductDto.cs | 1 - .../CreatePurchaseProductEndpoint.cs | 66 ++++++++++++------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs index a4d5234..8278f17 100644 --- a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs @@ -10,7 +10,6 @@ public class GetPurchaseProductDto public int ProductApprovalNumber { get; set; } public decimal ProductWeight { get; set; } public decimal ProductNec { get; set; } - public decimal ProductSellingPrice { get; set; } public string? ProductImage { get; set; } public string? ProductLink { get; set; } public int ProductMinimalQuantity { get; set; } diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs index 56ab3a9..b688d4a 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs @@ -5,7 +5,8 @@ using PyroFetes.DTO.PurchaseProduct.Response; namespace PyroFetes.Endpoints.PurchaseProduct; -public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint +public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) + : Endpoint { public override void Configure() { @@ -15,38 +16,59 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) { - var purchaseOrderExists = await database.PurchaseOrders.FirstOrDefaultAsync(a => a.Id == req.PurchaseOrderId, ct); - - if (purchaseOrderExists == null) + // Vérifie que le produit existe + var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); + if (product == null) { - await Send.NoContentAsync(ct); + await Send.NotFoundAsync(ct); return; } - + + // Si la commande existe déjà, on la récupère + var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct); + + // Si elle n'existe pas, on la crée + if (purchaseOrder == null) + { + purchaseOrder = new Models.PurchaseOrder() + { + PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" + }; + database.PurchaseOrders.Add(purchaseOrder); + await database.SaveChangesAsync(ct); // important pour avoir l'Id + } + + // Création du lien produit-commande var purchaseProduct = new Models.PurchaseProduct() { - ProductId = req.ProductId, - PurchaseOrderId = req.PurchaseOrderId, + ProductId = product.Id, + PurchaseOrderId = purchaseOrder.Id, Quantity = req.Quantity }; + database.PurchaseProducts.Add(purchaseProduct); - - var purchaseOrder = new Models.PurchaseOrder() - { - PurchaseConditions = req.PurchaseOrderPurchaseConditions, - }; - database.PurchaseOrders.Add(purchaseOrder); - await database.SaveChangesAsync(ct); - - GetPurchaseProductDto responseDto = new() + + // Prépare la réponse + var responseDto = new GetPurchaseProductDto() { - ProductId = purchaseProduct.ProductId, - PurchaseOrderId = purchaseProduct.PurchaseOrderId, - Quantity = purchaseProduct.Quantity, + ProductId = product.Id, + ProductReferences = int.TryParse(product.Reference, out var refInt) ? refInt : 0, + ProductName = product.Name, + ProductDuration = product.Duration, + ProductCaliber = product.Caliber, + ProductApprovalNumber = product.ApprovalNumber, + ProductWeight = product.Weight, + ProductNec = product.Nec, + ProductImage = product.Image, + ProductLink = product.Link, + ProductMinimalQuantity = product.MinimalQuantity, + + PurchaseOrderId = purchaseOrder.Id, PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions, + Quantity = purchaseProduct.Quantity }; - + await Send.OkAsync(responseDto, ct); } -} \ No newline at end of file +} From 347003c24a7e86f3bd74f19c5fb8475090f76998 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 18:40:30 +0100 Subject: [PATCH 3/6] updating CreatePurchaseProductEndpoint.cs and GetPurchaseProductDto.cs --- .../Response/GetPurchaseProductDto.cs | 2 +- .../CreatePurchaseProductEndpoint.cs | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs index 8278f17..d086ed3 100644 --- a/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Response/GetPurchaseProductDto.cs @@ -3,7 +3,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Response; public class GetPurchaseProductDto { public int ProductId { get; set; } - public int ProductReferences { get; set; } + public string? ProductReferences { get; set; } public string? ProductName { get; set; } public decimal ProductDuration {get; set;} public decimal ProductCaliber { get; set; } diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs index b688d4a..0578342 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs @@ -16,18 +16,15 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) { - // Vérifie que le produit existe var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); if (product == null) { await Send.NotFoundAsync(ct); return; } - - // Si la commande existe déjà, on la récupère + var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct); - - // Si elle n'existe pas, on la crée + if (purchaseOrder == null) { purchaseOrder = new Models.PurchaseOrder() @@ -35,25 +32,22 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" }; database.PurchaseOrders.Add(purchaseOrder); - await database.SaveChangesAsync(ct); // important pour avoir l'Id + await database.SaveChangesAsync(ct); } - - // Création du lien produit-commande + var purchaseProduct = new Models.PurchaseProduct() { ProductId = product.Id, PurchaseOrderId = purchaseOrder.Id, Quantity = req.Quantity }; - database.PurchaseProducts.Add(purchaseProduct); await database.SaveChangesAsync(ct); - - // Prépare la réponse + var responseDto = new GetPurchaseProductDto() { ProductId = product.Id, - ProductReferences = int.TryParse(product.Reference, out var refInt) ? refInt : 0, + ProductReferences = product.Reference, ProductName = product.Name, ProductDuration = product.Duration, ProductCaliber = product.Caliber, From b4502ae5620d53fb0245b12747a694f2ba87781b Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 18:48:55 +0100 Subject: [PATCH 4/6] editing dto from purchaseproduct --- .../Request/PatchPurchaseProductQuantityDto.cs | 3 ++- .../PurchaseProduct/Request/UpdatePurchaseProductDto.cs | 7 +++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PyroFetes/DTO/PurchaseProduct/Request/PatchPurchaseProductQuantityDto.cs b/PyroFetes/DTO/PurchaseProduct/Request/PatchPurchaseProductQuantityDto.cs index 9389244..8bd9499 100644 --- a/PyroFetes/DTO/PurchaseProduct/Request/PatchPurchaseProductQuantityDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Request/PatchPurchaseProductQuantityDto.cs @@ -2,6 +2,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request; public class PatchPurchaseProductQuantityDto { - public int Id { get; set; } + public int ProductId { get; set; } + public int PurchaseOrderId { get; set; } public int Quantity { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/PurchaseProduct/Request/UpdatePurchaseProductDto.cs b/PyroFetes/DTO/PurchaseProduct/Request/UpdatePurchaseProductDto.cs index 0b2f039..ea6b7ae 100644 --- a/PyroFetes/DTO/PurchaseProduct/Request/UpdatePurchaseProductDto.cs +++ b/PyroFetes/DTO/PurchaseProduct/Request/UpdatePurchaseProductDto.cs @@ -2,10 +2,11 @@ namespace PyroFetes.DTO.PurchaseProduct.Request; public class UpdatePurchaseProductDto { - public int Id { get; set; } + public int ProductId { get; set; } + public int PurchaseOrderId { get; set; } + public int Quantity { get; set; } - public int ProductId { get; set; } public int ProductReferences { get; set; } public string? ProductName { get; set; } public decimal ProductDuration {get; set;} @@ -17,7 +18,5 @@ public class UpdatePurchaseProductDto public string? ProductLink { get; set; } public int ProductMinimalQuantity { get; set; } - - public int PurchaseOrderId { get; set; } public string? PurchaseOrderPurchaseConditions { get; set; } } \ No newline at end of file From 791eff92562b76d61869292d255800cb58c967b3 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 19:32:31 +0100 Subject: [PATCH 5/6] added --- .../CreatePurchaseProductEndpoint.cs | 3 +- .../DeletePurchaseProductEndpoint.cs | 39 ++++++++++++++++++- .../UpdatePurchaseProductEndpoint.cs | 6 --- 3 files changed, 38 insertions(+), 10 deletions(-) delete mode 100644 PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs index 0578342..f060c3a 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs @@ -5,8 +5,7 @@ using PyroFetes.DTO.PurchaseProduct.Response; namespace PyroFetes.Endpoints.PurchaseProduct; -public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) - : Endpoint +public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint { public override void Configure() { diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs index 1f532ff..7af1030 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs @@ -1,6 +1,41 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; + namespace PyroFetes.Endpoints.PurchaseProduct; -public class DeletePurchaseProductEndpoint +public class DeletePurchaseOrderRequest { - + public int Id { get; set; } +} + +public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Delete("/api/purchaseOrders/{Id:int}"); + AllowAnonymous(); + } + + public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct) + { + var purchaseOrder = await database.PurchaseOrders + .Include(po => po.PurchaseProducts) + .SingleOrDefaultAsync(po => po.Id == req.Id, ct); + + if (purchaseOrder == null) + { + await Send.NotFoundAsync(ct); + return; + } + + if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any()) + { + database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts); + } + + database.PurchaseOrders.Remove(purchaseOrder); + await database.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs deleted file mode 100644 index 3373ae9..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/UpdatePurchaseProductEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class UpdatePurchaseProductEndpoint -{ - -} \ No newline at end of file From e4e6c1c3f7cfa5c918b6516c318a40e44b16d48b Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 16 Oct 2025 22:53:14 +0100 Subject: [PATCH 6/6] creating purchaseproduct's endpoint and fix error in dto --- .../Request/CreateDeliveryNoteDto.cs | 1 - .../PatchDeliveryNoteRealDeliveryDateDto.cs | 1 - .../Request/UpdateDeliveryNoteDto.cs | 1 - .../Response/GetDeliveryNoteDto.cs | 2 +- ...PatchPurchaseOrderPurchaseConditionsDto.cs | 7 ++++ .../Response/GetPurchaseOrderDto.cs | 7 ++++ .../DTO/User/Request/PatchUserPasswordDto.cs | 7 ++++ .../DeletePurchaseProductEndpoint.cs | 2 +- .../GetAllPurchasesProductsEndpoint.cs | 6 ---- .../GetPurchaseProductEndpoint.cs | 6 ---- .../PatchPurchaseProductQuantityEndpoint.cs | 34 +++++++++++++++++-- 11 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 PyroFetes/DTO/PurchaseOrder/Request/PatchPurchaseOrderPurchaseConditionsDto.cs create mode 100644 PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs create mode 100644 PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs delete mode 100644 PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs delete mode 100644 PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs diff --git a/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs b/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs index 5e0990d..f862856 100644 --- a/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs +++ b/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs @@ -8,5 +8,4 @@ public class CreateDeliveryNoteDto public DateOnly RealDeliveryDate { get; set; } public int DelivererId { get; set; } - } \ No newline at end of file diff --git a/PyroFetes/DTO/DeliveryNote/Request/PatchDeliveryNoteRealDeliveryDateDto.cs b/PyroFetes/DTO/DeliveryNote/Request/PatchDeliveryNoteRealDeliveryDateDto.cs index 486df5e..eb2182e 100644 --- a/PyroFetes/DTO/DeliveryNote/Request/PatchDeliveryNoteRealDeliveryDateDto.cs +++ b/PyroFetes/DTO/DeliveryNote/Request/PatchDeliveryNoteRealDeliveryDateDto.cs @@ -4,5 +4,4 @@ public class PatchDeliveryNoteRealDeliveryDateDto { public int Id { get; set; } public DateOnly RealDeliveryDate { get; set; } - } \ No newline at end of file diff --git a/PyroFetes/DTO/DeliveryNote/Request/UpdateDeliveryNoteDto.cs b/PyroFetes/DTO/DeliveryNote/Request/UpdateDeliveryNoteDto.cs index 1ab7cbf..b4746ff 100644 --- a/PyroFetes/DTO/DeliveryNote/Request/UpdateDeliveryNoteDto.cs +++ b/PyroFetes/DTO/DeliveryNote/Request/UpdateDeliveryNoteDto.cs @@ -9,5 +9,4 @@ public class UpdateDeliveryNoteDto public DateOnly? RealDeliveryDate { get; set; } public int DelivererId { get; set; } - } \ No newline at end of file diff --git a/PyroFetes/DTO/DeliveryNote/Response/GetDeliveryNoteDto.cs b/PyroFetes/DTO/DeliveryNote/Response/GetDeliveryNoteDto.cs index 6b4ffc7..3683ed3 100644 --- a/PyroFetes/DTO/DeliveryNote/Response/GetDeliveryNoteDto.cs +++ b/PyroFetes/DTO/DeliveryNote/Response/GetDeliveryNoteDto.cs @@ -13,5 +13,5 @@ public class GetDeliveryNoteDto public int DelivererId { get; set; } public string? DelivererTransporter { get; set; } - public List Products { get; set; } + public List? Products { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/PurchaseOrder/Request/PatchPurchaseOrderPurchaseConditionsDto.cs b/PyroFetes/DTO/PurchaseOrder/Request/PatchPurchaseOrderPurchaseConditionsDto.cs new file mode 100644 index 0000000..77586b0 --- /dev/null +++ b/PyroFetes/DTO/PurchaseOrder/Request/PatchPurchaseOrderPurchaseConditionsDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.PurchaseOrder.Request; + +public class PatchPurchaseOrderPurchaseConditionsDto +{ + public int Id { get; set; } + public string? PurchaseConditions { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs b/PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs new file mode 100644 index 0000000..38a012f --- /dev/null +++ b/PyroFetes/DTO/PurchaseOrder/Response/GetPurchaseOrderDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.PurchaseOrder.Response; + +public class GetPurchaseOrderDto +{ + public int Id { get; set; } + public string? PurchaseConditions { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs b/PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs new file mode 100644 index 0000000..bfa2051 --- /dev/null +++ b/PyroFetes/DTO/User/Request/PatchUserPasswordDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.User.Request; + +public class PatchUserPasswordDto +{ + public int Id { get; set; } + public string? Password { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs index 7af1030..5a02644 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs @@ -12,7 +12,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint { public override void Configure() { - Delete("/api/purchaseOrders/{Id:int}"); + Delete("/api/purchaseOrders/{Id}", x => new {x.Id}); AllowAnonymous(); } diff --git a/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs deleted file mode 100644 index 54517ff..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/GetAllPurchasesProductsEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class GetAllPurchasesProductsEndpoint -{ - -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs deleted file mode 100644 index 9527e4c..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/GetPurchaseProductEndpoint.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class GetPurchaseProductEndpoint -{ - -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs index 7772a82..dd53757 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs @@ -1,6 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.DTO.PurchaseProduct.Response; + namespace PyroFetes.Endpoints.PurchaseProduct; -public class PatchPurchaseProductQuantityEndpoint +public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint { - + public override void Configure() + { + Patch("/api/purchaseOrders/{ProductId}/{PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct) + { + var purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); + if (purchaseProduct == null) + { + await Send.NotFoundAsync(ct); + return; + } + + purchaseProduct.Quantity = req.Quantity; + await database.SaveChangesAsync(ct); + + GetPurchaseProductDto responseDto = new() + { + ProductId = purchaseProduct.ProductId, + PurchaseOrderId = purchaseProduct.PurchaseOrderId, + Quantity = purchaseProduct.Quantity + }; + await Send.OkAsync(responseDto, ct); + } } \ No newline at end of file