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 @@ + +