diff --git a/PyroFetes/DTO/WareHouseProduct/Request/CreateWareHouseProductDto.cs b/PyroFetes/DTO/WareHouseProduct/Request/CreateWareHouseProductDto.cs deleted file mode 100644 index 9b2a142..0000000 --- a/PyroFetes/DTO/WareHouseProduct/Request/CreateWareHouseProductDto.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace PyroFetes.DTO.WareHouseProduct.Request; - -public class CreateWareHouseProductDto -{ - public int Quantity { get; set; } - - public int WareHouseId { get; set; } - public string? WareHouseName {get; set;} - public int WareHouseMaxWeight {get; set;} - public int WareHouseCurrent {get; set;} - public int WareHouseMinWeight {get; set;} - public string? WareHouseAddress { get; set; } - public int WareHouseZipCode { get; set; } - public string? WareHouseCity { 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; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/WareHouseProduct/Request/PatchWareHouseProductQuantityDto.cs b/PyroFetes/DTO/WareHouseProduct/Request/PatchWareHouseProductQuantityDto.cs index 6bc95ad..b7a36e4 100644 --- a/PyroFetes/DTO/WareHouseProduct/Request/PatchWareHouseProductQuantityDto.cs +++ b/PyroFetes/DTO/WareHouseProduct/Request/PatchWareHouseProductQuantityDto.cs @@ -2,6 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Request; public class PatchWareHouseProductQuantityDto { - public int Id { get; set; } + public int WareHouseId { get; set; } + public int ProductId { get; set; } public int Quantity { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/WareHouseProduct/Request/UpdateWareHouseProductDto.cs b/PyroFetes/DTO/WareHouseProduct/Request/UpdateWareHouseProductDto.cs deleted file mode 100644 index 299d0c3..0000000 --- a/PyroFetes/DTO/WareHouseProduct/Request/UpdateWareHouseProductDto.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace PyroFetes.DTO.WareHouseProduct.Request; - -public class UpdateWareHouseProductDto -{ - public int Id { get; set; } - public int Quantity { get; set; } - - public int WareHouseId { get; set; } - public string? WareHouseName {get; set;} - public int WareHouseMaxWeight {get; set;} - public int WareHouseCurrent {get; set;} - public int WareHouseMinWeight {get; set;} - public string? WareHouseAddress { get; set; } - public int WareHouseZipCode { get; set; } - public string? WareHouseCity { 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; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/WareHouseProduct/Response/GetTotalQuantityDto.cs b/PyroFetes/DTO/WareHouseProduct/Response/GetTotalQuantityDto.cs new file mode 100644 index 0000000..01701c9 --- /dev/null +++ b/PyroFetes/DTO/WareHouseProduct/Response/GetTotalQuantityDto.cs @@ -0,0 +1,7 @@ +namespace PyroFetes.DTO.WareHouseProduct.Response; + +public class GetTotalQuantityDto +{ + public int ProductId { get; set; } + public int TotalQuantity { get; set; } +} \ No newline at end of file diff --git a/PyroFetes/DTO/WareHouseProduct/Response/GetWareHouseProductDto.cs b/PyroFetes/DTO/WareHouseProduct/Response/GetWareHouseProductDto.cs index 70a1e4a..947b6c0 100644 --- a/PyroFetes/DTO/WareHouseProduct/Response/GetWareHouseProductDto.cs +++ b/PyroFetes/DTO/WareHouseProduct/Response/GetWareHouseProductDto.cs @@ -2,27 +2,7 @@ namespace PyroFetes.DTO.WareHouseProduct.Response; public class GetWareHouseProductDto { - public int Id { get; set; } public int Quantity { get; set; } - public int WareHouseId { get; set; } - public string? WareHouseName {get; set;} - public int WareHouseMaxWeight {get; set;} - public int WareHouseCurrent {get; set;} - public int WareHouseMinWeight {get; set;} - public string? WareHouseAddress { get; set; } - public int WareHouseZipCode { get; set; } - public string? WareHouseCity { 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; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs index e0c36e6..ada8499 100644 --- a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs @@ -1,11 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseProduct.Request; -using PyroFetes.DTO.PurchaseProduct.Response; using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Response; -namespace PyroFetes.Endpoints.QuoationProduct; +namespace PyroFetes.Endpoints.QuotationProduct; public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint { diff --git a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs index 0f14336..fa38341 100644 --- a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs @@ -1,7 +1,7 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -namespace PyroFetes.Endpoints.QuoationProduct; +namespace PyroFetes.Endpoints.QuotationProduct; public class DeleteQuotationProductRequest { diff --git a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs b/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs index 424228a..d6b043a 100644 --- a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Response; -namespace PyroFetes.Endpoints.QuoationProduct; +namespace PyroFetes.Endpoints.QuotationProduct; public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint { diff --git a/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs new file mode 100644 index 0000000..c5921f0 --- /dev/null +++ b/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs @@ -0,0 +1,42 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.WareHouseProduct.Response; + +namespace PyroFetes.Endpoints.WareHouseProduct; + +public class GetTotalQuantityRequest +{ + public int ProductId { get; set; } +} + +public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Get("/api/wareHouseProduct/{ProductId}", x => new { x.ProductId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct) + { + bool exists = await database.WarehouseProducts + .AnyAsync(wp => wp.ProductId == req.ProductId, ct); + + if (!exists) + { + await Send.NotFoundAsync(ct); + return; + } + + var totalQuantity = await database.WarehouseProducts + .Where(wp => wp.ProductId == req.ProductId) + .SumAsync(wp => wp.Quantity, ct); + + GetTotalQuantityDto responseDto = new() + { + ProductId = req.ProductId, + TotalQuantity = totalQuantity + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs new file mode 100644 index 0000000..fee191d --- /dev/null +++ b/PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.QuotationProduct.Request; +using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.DTO.WareHouseProduct.Request; +using PyroFetes.DTO.WareHouseProduct.Response; + +namespace PyroFetes.Endpoints.WareHouseProduct; + +public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Patch("/api/wareHouseProduct/{ProductId}/{WareHouseId}/Quantity", x => new { x.ProductId, x.WareHouseId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct) + { + var wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct); + if (wareHouseProduct == null) + { + await Send.NotFoundAsync(ct); + return; + } + + wareHouseProduct.Quantity = req.Quantity; + await database.SaveChangesAsync(ct); + + GetWareHouseProductDto responseDto = new() + { + ProductId = wareHouseProduct.ProductId, + WareHouseId = wareHouseProduct.WarehouseId, + Quantity = wareHouseProduct.Quantity + }; + await Send.OkAsync(responseDto, ct); + } +} \ No newline at end of file