From be0a6a40042a0a70883989c7ae85d367fa5c22d6 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 6 Nov 2025 17:30:03 +0100 Subject: [PATCH 1/8] Creating supplier's endpoints --- .../Supplier/CreateSupplierEndpoint.cs | 43 +++++++++++++++++ .../Supplier/DeleteSupplierEndpoint.cs | 33 +++++++++++++ .../Supplier/GetAllSuppliersEndpoint.cs | 32 +++++++++++++ .../Endpoints/Supplier/GetSupplierEndpoint.cs | 43 +++++++++++++++++ .../PatchSupplierDeleveryDelayEndpoint.cs | 36 ++++++++++++++ .../Supplier/UpdateSupplierEndpoint.cs | 48 +++++++++++++++++++ 6 files changed, 235 insertions(+) create mode 100644 PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs create mode 100644 PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs create mode 100644 PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs create mode 100644 PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs create mode 100644 PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs create mode 100644 PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs diff --git a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs new file mode 100644 index 0000000..6232481 --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs @@ -0,0 +1,43 @@ +using PyroFetes.DTO.Supplier.Request; +using PyroFetes.DTO.Supplier.Response; +using FastEndpoints; + +namespace PyroFetes.Endpoints.Supplier; + +public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Post("/api/suppliers"); + } + + public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) + { + var supplier = new Models.Supplier() + { + Name = req.Name, + Email = req.Email, + Phone = req.Phone, + Address = req.Address, + City = req.City, + ZipCode = req.ZipCode, + DeliveryDelay = req.DeliveryDelay + }; + + database.Suppliers.Add(supplier); + await database.SaveChangesAsync(ct); + + GetSupplierDto responseDto = new() + { + Id = supplier.Id, + Name = supplier.Name, + Email = supplier.Email, + Phone = supplier.Phone, + Address = supplier.Address, + City = supplier.City, + ZipCode = supplier.ZipCode, + DeliveryDelay = supplier.DeliveryDelay + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs new file mode 100644 index 0000000..28b4487 --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs @@ -0,0 +1,33 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; + +namespace PyroFetes.Endpoints.Supplier; + +public class DeleteSupplierRequest +{ + public int Id { get; set; } +} + +public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Delete("/api/suppliers/{@Id}", x => new {x.Id}); + } + + public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct) + { + var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + database.Suppliers.Remove(supplier); + await database.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs new file mode 100644 index 0000000..b550c85 --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs @@ -0,0 +1,32 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.DTO.Supplier.Response; + +namespace PyroFetes.Endpoints.Supplier; + +public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("/api/suppliers"); + } + + public override async Task HandleAsync(CancellationToken ct) + { + var supplier = await database.Suppliers + .Select(supplier => new GetSupplierDto() + { + Id = supplier.Id, + Name = supplier.Name, + Email = supplier.Email, + Phone = supplier.Phone, + Address = supplier.Address, + City = supplier.City, + ZipCode = supplier.ZipCode, + DeliveryDelay = supplier.DeliveryDelay + }).ToListAsync(ct); + + await Send.OkAsync(supplier, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs new file mode 100644 index 0000000..40b6e8e --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs @@ -0,0 +1,43 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Supplier.Response; + +namespace PyroFetes.Endpoints.Supplier; + +public class GetSupplierRequest +{ + public int Id { get; set; } +} + +public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/suppliers/{@Id}", x => new {x.Id}); + } + + public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) + { + var supplier = await database.Suppliers + .SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetSupplierDto responseDto = new() + { + Id = supplier.Id, + Name = supplier.Name, + Email = supplier.Email, + Phone = supplier.Phone, + Address = supplier.Address, + City = supplier.City, + ZipCode = supplier.ZipCode, + DeliveryDelay = supplier.DeliveryDelay + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs new file mode 100644 index 0000000..ea31903 --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Supplier.Request; +using PyroFetes.DTO.Supplier.Response; + +namespace PyroFetes.Endpoints.Supplier; + +public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); + } + + public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) + { + var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + supplier.DeliveryDelay = req.DeliveryDelay; + await database.SaveChangesAsync(ct); + + GetSupplierDto responseDto = new() + { + Id = supplier.Id, + DeliveryDelay = supplier.DeliveryDelay, + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs new file mode 100644 index 0000000..ab68ebb --- /dev/null +++ b/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs @@ -0,0 +1,48 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Supplier.Request; +using PyroFetes.DTO.Supplier.Response; + +namespace PyroFetes.Endpoints.Supplier; + +public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Put("/api/suppliers/{@Id}", x => new {x.Id}); + } + + public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct) + { + var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + supplier.Name = req.Name; + supplier.Email = req.Email; + supplier.Phone = req.Phone; + supplier.Address = req.Address; + supplier.City = req.City; + supplier.ZipCode = req.ZipCode; + supplier.DeliveryDelay = req.DeliveryDelay; + await database.SaveChangesAsync(ct); + + GetSupplierDto responseDto = new() + { + Id = supplier.Id, + Name = supplier.Name, + Email = supplier.Email, + Phone = supplier.Phone, + Address = supplier.Address, + City = supplier.City, + ZipCode = supplier.ZipCode, + DeliveryDelay = supplier.DeliveryDelay + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file From 33719b708e7fd705b83690a8e120fc7dcf9185f1 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 6 Nov 2025 18:52:18 +0100 Subject: [PATCH 2/8] Creating of price's endpoints --- PyroFetes/DTO/Price/Request/CreatePriceDto.cs | 2 +- .../Request/PatchPriceSellingPriceDto.cs | 3 +- .../Endpoints/Price/CreatePriceEndpoint.cs | 83 +++++++++++++++++++ .../Endpoints/Price/DeletePriceEndpoint.cs | 36 ++++++++ .../Endpoints/Price/PatchPriceEndpoint.cs | 36 ++++++++ 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs create mode 100644 PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs create mode 100644 PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs diff --git a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs index f268d21..046c064 100644 --- a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs +++ b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs @@ -14,7 +14,7 @@ public class CreatePriceDto public int SupplierDeliveryDelay { get; set; } 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/DTO/Price/Request/PatchPriceSellingPriceDto.cs b/PyroFetes/DTO/Price/Request/PatchPriceSellingPriceDto.cs index 5692248..3dd1b6b 100644 --- a/PyroFetes/DTO/Price/Request/PatchPriceSellingPriceDto.cs +++ b/PyroFetes/DTO/Price/Request/PatchPriceSellingPriceDto.cs @@ -2,6 +2,7 @@ public class PatchPriceSellingPriceDto { - public int Id { get; set; } + public int ProductId { get; set; } + public int SupplierId { get; set; } public decimal SellingPrice { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs new file mode 100644 index 0000000..79b3060 --- /dev/null +++ b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs @@ -0,0 +1,83 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Price.Request; +using PyroFetes.DTO.Price.Response; + +namespace PyroFetes.Endpoints.Price; + +public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Post("/api/prices"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct) + { + var price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + if (price == null) + { + await Send.NotFoundAsync(ct); + return; + } + + var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct); + + var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct); + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + if (supplier == null) + { + supplier = new Models.Supplier() + { + Name = req.SupplierName, + Email = req.SupplierEmail, + Phone = req.SupplierPhone, + Address = req.SupplierAddress, + City = req.SupplierCity, + ZipCode = req.SupplierZipCode, + DeliveryDelay = req.SupplierDeliveryDelay + + }; + database.Suppliers.Add(supplier); + await database.SaveChangesAsync(ct); + } + + var priceAdded = new Models.Price() + { + SellingPrice = price.SellingPrice, + SupplierId = supplier.Id, + ProductId = product.Id, + }; + database.Prices.Add(priceAdded); + await database.SaveChangesAsync(ct); + + var productAdded = new Models.Product() + { + Reference = req.ProductReferences, + Name = req.ProductName, + Duration = req.ProductDuration, + Caliber = req.ProductCaliber, + ApprovalNumber = req.ProductApprovalNumber, + Weight = req.ProductWeight, + Nec = req.ProductNec, + Image = req.ProductImage, + Link = req.ProductLink, + MinimalQuantity = req.ProductMinimalQuantity + }; + database.Products.Add(productAdded); + await database.SaveChangesAsync(ct); + + var responseDto = new GetPriceDto() + { + + }; + + await Send.OkAsync(responseDto, ct); + } +} diff --git a/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs new file mode 100644 index 0000000..bb289c9 --- /dev/null +++ b/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; + +namespace PyroFetes.Endpoints.QuotationProduct; + +public class DeletePriceRequest +{ + public int ProductId { get; set; } + public int SupplierId { get; set; } +} + +public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId}); + AllowAnonymous(); + } + + public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct) + { + var price = await database.Prices + .SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + + if (price == null) + { + await Send.NotFoundAsync(ct); + return; + } + + database.Prices.Remove(price); + await database.SaveChangesAsync(ct); + + await Send.NoContentAsync(ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs b/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs new file mode 100644 index 0000000..05dbdb8 --- /dev/null +++ b/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Price.Request; +using PyroFetes.DTO.Price.Response; + +namespace PyroFetes.Endpoints.Price; + +public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct) + { + var price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + if (price == null) + { + await Send.NotFoundAsync(ct); + return; + } + + price.SellingPrice = req.SellingPrice; + await database.SaveChangesAsync(ct); + + GetPriceDto responseDto = new() + { + ProductId = price.ProductId, + SupplierId = price.SupplierId, + SellingPrice = price.SellingPrice + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file From a535f8cfebc3e598ffd6978b9c6c032727b70774 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 6 Nov 2025 18:51:46 +0100 Subject: [PATCH 3/8] fix errors in Price's DTO --- PyroFetes/DTO/Price/Request/UpdatePriceDto.cs | 2 +- PyroFetes/DTO/Price/Response/GetPriceDto.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PyroFetes/DTO/Price/Request/UpdatePriceDto.cs b/PyroFetes/DTO/Price/Request/UpdatePriceDto.cs index 6f6af24..1eac827 100644 --- a/PyroFetes/DTO/Price/Request/UpdatePriceDto.cs +++ b/PyroFetes/DTO/Price/Request/UpdatePriceDto.cs @@ -15,7 +15,7 @@ public class UpdatePriceDto public int SupplierDeliveryDelay { get; set; } 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/DTO/Price/Response/GetPriceDto.cs b/PyroFetes/DTO/Price/Response/GetPriceDto.cs index 81a8f07..a042cd2 100644 --- a/PyroFetes/DTO/Price/Response/GetPriceDto.cs +++ b/PyroFetes/DTO/Price/Response/GetPriceDto.cs @@ -15,7 +15,7 @@ public class GetPriceDto public int SupplierDeliveryDelay { get; set; } 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; } From f8b3c5143520c7eaaa57fbce68ef16e27c15bd8d Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Thu, 6 Nov 2025 19:25:35 +0100 Subject: [PATCH 4/8] fix error on CreatePriceEndpoint.cs --- .../Endpoints/Price/CreatePriceEndpoint.cs | 64 ++++++++++++------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs index 79b3060..71dbb1e 100644 --- a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs @@ -15,22 +15,7 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); - if (price == null) - { - await Send.NotFoundAsync(ct); - return; - } - var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct); - - var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct); - if (product == null) - { - await Send.NotFoundAsync(ct); - return; - } - if (supplier == null) { supplier = new Models.Supplier() @@ -48,14 +33,12 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint p.Reference == req.ProductReferences, ct); + if (product != null) { - SellingPrice = price.SellingPrice, - SupplierId = supplier.Id, - ProductId = product.Id, - }; - database.Prices.Add(priceAdded); - await database.SaveChangesAsync(ct); + await Send.NotFoundAsync(ct); + return; + } var productAdded = new Models.Product() { @@ -73,9 +56,44 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + if (price != null) + { + await Send.NotFoundAsync(ct); + return; + } + + var priceAdded = new Models.Price() + { + SellingPrice = req.SellingPrice, + SupplierId = supplier.Id, + ProductId = productAdded.Id, + }; + database.Prices.Add(priceAdded); + await database.SaveChangesAsync(ct); + var responseDto = new GetPriceDto() { - + SellingPrice = priceAdded.SellingPrice, + SupplierId = supplier.Id, + ProductId = productAdded.Id, + SupplierName = supplier.Name, + SupplierEmail = supplier.Email, + SupplierPhone = supplier.Phone, + SupplierAddress = supplier.Address, + SupplierCity = supplier.City, + SupplierZipCode = supplier.ZipCode, + SupplierDeliveryDelay = supplier.DeliveryDelay, + ProductReferences = productAdded.Reference, + ProductName = productAdded.Name, + ProductDuration = productAdded.Duration, + ProductCaliber = productAdded.Caliber, + ProductApprovalNumber = productAdded.ApprovalNumber, + ProductWeight = productAdded.Weight, + ProductNec = productAdded.Nec, + ProductImage = productAdded.Image, + ProductLink = productAdded.Link, + ProductMinimalQuantity = productAdded.MinimalQuantity }; await Send.OkAsync(responseDto, ct); From 97a7c6811c727ca705ad1f256324c93238d177b3 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Fri, 7 Nov 2025 17:41:50 +0100 Subject: [PATCH 5/8] created product's endpoints --- .../DTO/Product/Request/CreateProductDto.cs | 2 +- .../DTO/Product/Request/UpdateProductDto.cs | 2 +- .../DTO/Product/Response/GetProductDto.cs | 2 +- .../Product/GetAllProductsEndpoint.cs | 36 +++++++++++++ .../Endpoints/Product/GetProductEndpoint.cs | 48 +++++++++++++++++ .../PatchProductMinimalStockEndpoint.cs | 46 ++++++++++++++++ .../Product/UpdateProductEndpoint.cs | 54 +++++++++++++++++++ 7 files changed, 187 insertions(+), 3 deletions(-) create mode 100644 PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs create mode 100644 PyroFetes/Endpoints/Product/GetProductEndpoint.cs create mode 100644 PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs create mode 100644 PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs diff --git a/PyroFetes/DTO/Product/Request/CreateProductDto.cs b/PyroFetes/DTO/Product/Request/CreateProductDto.cs index 24ecf17..44c38c4 100644 --- a/PyroFetes/DTO/Product/Request/CreateProductDto.cs +++ b/PyroFetes/DTO/Product/Request/CreateProductDto.cs @@ -2,7 +2,7 @@ namespace PyroFetes.DTO.Product.Request; public class CreateProductDto { - public int References { get; set; } + public string? References { get; set; } public string? Name { get; set; } public decimal Duration {get; set;} public decimal Caliber { get; set; } diff --git a/PyroFetes/DTO/Product/Request/UpdateProductDto.cs b/PyroFetes/DTO/Product/Request/UpdateProductDto.cs index 0548119..23bb108 100644 --- a/PyroFetes/DTO/Product/Request/UpdateProductDto.cs +++ b/PyroFetes/DTO/Product/Request/UpdateProductDto.cs @@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Request; public class UpdateProductDto { public int Id { get; set; } - public int References { get; set; } + public string? References { get; set; } public string? Name { get; set; } public decimal Duration {get; set;} public decimal Caliber { get; set; } diff --git a/PyroFetes/DTO/Product/Response/GetProductDto.cs b/PyroFetes/DTO/Product/Response/GetProductDto.cs index 6781381..d31bfb5 100644 --- a/PyroFetes/DTO/Product/Response/GetProductDto.cs +++ b/PyroFetes/DTO/Product/Response/GetProductDto.cs @@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Response; public class GetProductDto { public int Id { get; set; } - public int References { get; set; } + public string? References { get; set; } public string? Name { get; set; } public decimal Duration {get; set;} public decimal Caliber { get; set; } diff --git a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs new file mode 100644 index 0000000..70ec082 --- /dev/null +++ b/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Response; +using PyroFetes.DTO.PurchaseProduct.Response; + +namespace PyroFetes.Endpoints.Product; + +public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("/api/products"); + } + + public override async Task HandleAsync(CancellationToken ct) + { + var product = await database.Products + .Select(product => new GetProductDto() + { + Id = product.Id, + References = product.Reference, + Name = product.Name, + Duration = product.Duration, + Caliber = product.Caliber, + ApprovalNumber = product.ApprovalNumber, + Weight = product.Weight, + Nec = product.Nec, + Image = product.Image, + Link = product.Link, + MinimalQuantity = product.MinimalQuantity, + }) + .ToListAsync(ct); + + await Send.OkAsync(product, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs b/PyroFetes/Endpoints/Product/GetProductEndpoint.cs new file mode 100644 index 0000000..72e3fa5 --- /dev/null +++ b/PyroFetes/Endpoints/Product/GetProductEndpoint.cs @@ -0,0 +1,48 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Response; +using PyroFetes.DTO.PurchaseProduct.Response; + +namespace PyroFetes.Endpoints.Product; + +public class GetProductRequest +{ + public int Id { get; set; } +} + +public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/products/{@Id}", x => new {x.Id}); + } + + public override async Task HandleAsync(GetProductRequest req, CancellationToken ct) + { + var product = await database.Products + .SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + GetProductDto responseDto = new() + { + Id = product.Id, + References = product.Reference, + Name = product.Name, + Duration = product.Duration, + Caliber = product.Caliber, + ApprovalNumber = product.ApprovalNumber, + Weight = product.Weight, + Nec = product.Nec, + Image = product.Image, + Link = product.Link, + MinimalQuantity = product.MinimalQuantity, + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs new file mode 100644 index 0000000..31ad504 --- /dev/null +++ b/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs @@ -0,0 +1,46 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Request; +using PyroFetes.DTO.Product.Response; +using PyroFetes.DTO.PurchaseProduct.Response; + +namespace PyroFetes.Endpoints.Product; + +public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) + : Endpoint +{ + public override void Configure() + { + Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) + { + var product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct); + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + product.MinimalQuantity = req.MinimalQuantity; + await database.SaveChangesAsync(ct); + + GetProductDto responseDto = new() + { + Id = product.Id, + References = product.Reference, + Name = product.Name, + Duration = product.Duration, + Caliber = product.Caliber, + ApprovalNumber = product.ApprovalNumber, + Weight = product.Weight, + Nec = product.Nec, + Image = product.Image, + Link = product.Link, + MinimalQuantity = product.MinimalQuantity, + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs new file mode 100644 index 0000000..856280f --- /dev/null +++ b/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs @@ -0,0 +1,54 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Request; +using PyroFetes.DTO.Product.Response; + +namespace PyroFetes.Endpoints.Product; + +public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Put("/api/products/{@Id}", x => new {x.Id}); + } + + public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct) + { + var product = await database.Products.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + product.Reference = req.References; + product.Name = req.Name; + product.Duration = req.Duration; + product.Caliber = req.Caliber; + product.ApprovalNumber = req.ApprovalNumber; + product.Weight = req.Weight; + product.Nec = req.Nec; + product.Image = req.Image; + product.Link = req.Link; + product.MinimalQuantity = req.MinimalQuantity; + await database.SaveChangesAsync(ct); + + GetProductDto responseDto = new() + { + Id = product.Id, + References = product.Reference, + Name = product.Name, + Duration = product.Duration, + Caliber = product.Caliber, + ApprovalNumber = product.ApprovalNumber, + Weight = product.Weight, + Nec = product.Nec, + Image = product.Image, + Link = product.Link, + MinimalQuantity = product.MinimalQuantity, + }; + + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file From 304c06ed19f2e56a7d2794faa9f4c92d98414fa7 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Fri, 7 Nov 2025 17:45:35 +0100 Subject: [PATCH 6/8] changed setting for SettingEndpoints --- .../{Setting => SettingEndpoints}/CreateSettingEndpoint.cs | 7 ++++--- .../{Setting => SettingEndpoints}/DeleteSettingEndpoint.cs | 2 +- .../{Setting => SettingEndpoints}/GetSettingEndpoint.cs | 2 +- .../PatchSettingElectronicSignatureEndpoint.cs | 2 +- .../PatchSettingLogoEndpoint.cs | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) rename PyroFetes/Endpoints/{Setting => SettingEndpoints}/CreateSettingEndpoint.cs (87%) rename PyroFetes/Endpoints/{Setting => SettingEndpoints}/DeleteSettingEndpoint.cs (94%) rename PyroFetes/Endpoints/{Setting => SettingEndpoints}/GetSettingEndpoint.cs (95%) rename PyroFetes/Endpoints/{Setting => SettingEndpoints}/PatchSettingElectronicSignatureEndpoint.cs (95%) rename PyroFetes/Endpoints/{Setting => SettingEndpoints}/PatchSettingLogoEndpoint.cs (95%) diff --git a/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs similarity index 87% rename from PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs rename to PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs index 11dcedd..93250d6 100644 --- a/PyroFetes/Endpoints/Setting/CreateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs @@ -1,7 +1,8 @@ -using PyroFetes.DTO.SettingDTO.Request; +using FastEndpoints; +using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; -using FastEndpoints; -namespace PyroFetes.Endpoints.Setting; + +namespace PyroFetes.Endpoints.SettingEndpoints; public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint { diff --git a/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs similarity index 94% rename from PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs rename to PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs index 92bfba7..0930566 100644 --- a/PyroFetes/Endpoints/Setting/DeleteSettingEndpoint.cs +++ b/PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs @@ -1,7 +1,7 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -namespace PyroFetes.Endpoints.Setting; +namespace PyroFetes.Endpoints.SettingEndpoints; public class DeleteSettingRequest { diff --git a/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs similarity index 95% rename from PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs rename to PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs index 9ebd72b..34b059d 100644 --- a/PyroFetes/Endpoints/Setting/GetSettingEndpoint.cs +++ b/PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Response; -namespace PyroFetes.Endpoints.Setting; +namespace PyroFetes.Endpoints.SettingEndpoints; public class GetSettingRequest { diff --git a/PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs similarity index 95% rename from PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs rename to PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs index c54d915..39e8459 100644 --- a/PyroFetes/Endpoints/Setting/PatchSettingElectronicSignatureEndpoint.cs +++ b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; -namespace PyroFetes.Endpoints.Setting; +namespace PyroFetes.Endpoints.SettingEndpoints; public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint { diff --git a/PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs similarity index 95% rename from PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs rename to PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs index 4bfe5c1..553800a 100644 --- a/PyroFetes/Endpoints/Setting/PatchSettingLogoEndpoint.cs +++ b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; -namespace PyroFetes.Endpoints.Setting; +namespace PyroFetes.Endpoints.SettingEndpoints; public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint { From 7d92f80de3672cfb6586d69c3bd7a9ff1dbeb5e6 Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Sun, 9 Nov 2025 18:46:24 +0100 Subject: [PATCH 7/8] Actualiser PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs --- .../Endpoints/Price/CreatePriceEndpoint.cs | 87 ++++++++++--------- 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs index 71dbb1e..d65ba2d 100644 --- a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs @@ -15,6 +15,7 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint s.Id == req.SupplierId, ct); if (supplier == null) { @@ -27,56 +28,58 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint p.Reference == req.ProductReferences, ct); - if (product != null) + + // Gestion du produit + var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct); + if (product == null) { - await Send.NotFoundAsync(ct); + product = new Models.Product() + { + Reference = req.ProductReferences, + Name = req.ProductName, + Duration = req.ProductDuration, + Caliber = req.ProductCaliber, + ApprovalNumber = req.ProductApprovalNumber, + Weight = req.ProductWeight, + Nec = req.ProductNec, + Image = req.ProductImage, + Link = req.ProductLink, + MinimalQuantity = req.ProductMinimalQuantity + }; + database.Products.Add(product); + await database.SaveChangesAsync(ct); + } + + // Vérifie si le prix existe déjà pour ce fournisseur et produit + var existingPrice = await database.Prices + .SingleOrDefaultAsync(p => p.ProductId == product.Id && p.SupplierId == supplier.Id, ct); + + if (existingPrice != null) + { + await Send.ConflictAsync("Le fournisseur a déjà un prix pour ce produit.", ct); return; } - - var productAdded = new Models.Product() - { - Reference = req.ProductReferences, - Name = req.ProductName, - Duration = req.ProductDuration, - Caliber = req.ProductCaliber, - ApprovalNumber = req.ProductApprovalNumber, - Weight = req.ProductWeight, - Nec = req.ProductNec, - Image = req.ProductImage, - Link = req.ProductLink, - MinimalQuantity = req.ProductMinimalQuantity - }; - database.Products.Add(productAdded); - await database.SaveChangesAsync(ct); - - var price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); - if (price != null) - { - await Send.NotFoundAsync(ct); - return; - } - + + // Création du prix var priceAdded = new Models.Price() { SellingPrice = req.SellingPrice, SupplierId = supplier.Id, - ProductId = productAdded.Id, + ProductId = product.Id }; database.Prices.Add(priceAdded); await database.SaveChangesAsync(ct); - + + // Création du DTO de réponse var responseDto = new GetPriceDto() { SellingPrice = priceAdded.SellingPrice, SupplierId = supplier.Id, - ProductId = productAdded.Id, + ProductId = product.Id, SupplierName = supplier.Name, SupplierEmail = supplier.Email, SupplierPhone = supplier.Phone, @@ -84,16 +87,16 @@ public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint Date: Sun, 9 Nov 2025 18:48:23 +0100 Subject: [PATCH 8/8] Actualiser PyroFetes/DTO/Price/Request/CreatePriceDto.cs --- PyroFetes/DTO/Price/Request/CreatePriceDto.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs index 046c064..b149ef6 100644 --- a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs +++ b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs @@ -4,7 +4,7 @@ public class CreatePriceDto { public decimal SellingPrice { get; set; } - public int SupplierId { get; set; } + public int? SupplierId { get; set; } public string? SupplierName { get; set; } public string? SupplierEmail { get; set; } public string? SupplierPhone { get; set; } @@ -13,7 +13,7 @@ public class CreatePriceDto public string? SupplierCity { get; set; } public int SupplierDeliveryDelay { get; set; } - public int ProductId { get; set; } + public int? ProductId { get; set; } public string? ProductReferences { get; set; } public string? ProductName { get; set; } public decimal ProductDuration {get; set;}