85 Commits

Author SHA1 Message Date
sanchezvem d17f2fb23e Implemented rustfs in app 2026-06-05 11:52:49 +01:00
sanchezvem 697e1431d9 Added validators to managed users 2026-06-01 10:55:32 +01:00
sanchezvem de6a1c5385 Actualiser README.md 2026-05-30 14:25:02 +02:00
sanchezvem 29759cf896 Fixed wwwroot error 2026-05-30 13:44:21 +01:00
sanchezvem f0ad9b536a Changed values of userDto 2026-05-28 15:50:57 +01:00
sanchezvem fb97729c71 Changed values of userDto 2026-05-28 15:41:07 +01:00
sanchezvem 1bd92a8732 Fix route error 2026-05-28 15:39:55 +01:00
sanchezvem 8c38255ed9 Merge remote-tracking branch 'origin/feature/refactor-backend' into feature/refactor-backend
# Conflicts:
#	PyroFetes/Endpoints/Users/GetUserEndpoint.cs
2026-05-28 15:39:04 +01:00
sanchezvem 639631a63b Changed Id value 2026-05-28 15:36:58 +01:00
Cristiano 5869ae18c4 Put roles into endpoints 2026-05-28 15:36:33 +02:00
sanchezvem fc9da89ebe Added refresh token endpoint 2026-05-28 14:05:47 +01:00
sanchezvem 76239b41bd Adapt endpoint to UX 2026-05-27 18:02:03 +01:00
sanchezvem 88882f9db8 Deleted date of delivery note dto 2026-05-27 17:48:30 +01:00
sanchezvem 6339fbdb8c Added spec for see all documents order by desc 2026-05-27 17:23:02 +01:00
sanchezvem 6f2c60e6c0 Fixed error with inclusion in pdf of quotation 2026-05-27 13:12:57 +01:00
sanchezvem cac880e35f Add endpoint to display all customers, and updated dto to create quotation and purchase order 2026-05-27 12:32:27 +01:00
sanchezvem 897b036fc5 fix error 2026-05-26 18:55:54 +01:00
sanchezvem 19c63ef317 Fixed error with update of quantity in stock page 2026-05-26 12:06:15 +01:00
sanchezvem fdaead91ff Changed display of delivery note 2026-05-26 12:01:09 +01:00
sanchezvem aa40ae2e7a Added missing mappings profiles 2026-05-26 11:43:41 +01:00
sanchezvem ed59efe4f8 Added new endpoint to manage warehouse 2026-05-26 11:16:16 +01:00
sanchezvem b13b8ebfb6 Added new endpoint to manage deliveries 2026-05-26 10:53:10 +01:00
sanchezvem 57646a1417 Fix error with spec of product under limit 2026-05-26 10:25:05 +01:00
sanchezvem 3cb619cfa6 Fixed error of display with price of product in all documents 2026-05-25 16:38:33 +01:00
sanchezvem 48b9db6e1c Added SupplierId in DeliveryNote 2026-05-25 16:21:58 +01:00
sanchezvem c0ac9f7a65 Fixed error with setting during conversion of base64 2026-05-25 15:42:23 +01:00
sanchezvem d46fa606b7 Fixed error with creation of document 2026-05-25 12:19:05 +01:00
sanchezvem b59a8b6c3d Added missing field to display price of products on quotation and purchase order 2026-05-25 11:44:18 +01:00
sanchezvem 1ae8072219 Fixed error with documentId 2026-05-25 11:09:01 +01:00
sanchezvem 1434a5d77a Cleaned code 2026-05-24 17:24:44 +01:00
sanchezvem 656100d15e Refactor all code 2026-05-24 17:22:03 +01:00
Cristiano fe58e5e7e7 Firs fixes like price into PDF 2026-03-26 17:23:09 +01:00
Cristiano 9c723a7a10 Merge remote-tracking branch 'origin/develop' into develop 2026-03-26 15:36:28 +01:00
Cristiano 0312f02028 Some fixes 2026-03-26 15:35:11 +01:00
sanchezvem 418c2b3d16 fix error 2025-12-20 15:39:05 +01:00
Cristiano 3487baad87 Added endpoint to get products under their limit 2025-12-18 14:41:45 +01:00
sanchezvem 29e2036965 fix error 2025-12-13 15:34:29 +01:00
sanchezvem be7a3193ab added CreateQuotationEndpoint.cs 2025-12-13 15:08:18 +01:00
sanchezvem 0802ec9e33 new migration 2025-12-13 11:39:56 +01:00
sanchezvem 35d3e58d86 fix error and add CreatePurchaseOrder.cs 2025-12-13 11:24:01 +01:00
sanchezvem 2a42e1010f fix error 2025-12-12 21:57:58 +01:00
sanchezvem 2fa74ccba8 added UpdateQuotationDto.cs 2025-12-12 21:18:13 +01:00
sanchezvem 65cff130e4 update deliverynote endpoint 2025-12-11 17:46:23 +01:00
sanchezvem e21e2afea4 fix error 2025-12-04 17:11:34 +01:00
sanchezvem 17978e7c19 change response in endpoint to generate pdf 2025-12-04 16:38:27 +01:00
sanchezvem 6a20676b32 added showcompagnon 2025-12-04 15:06:36 +01:00
sanchezvem e440dcd2b5 added pdf generation for all orders 2025-12-03 17:41:19 +01:00
sanchezvem bee1cfb0e3 added PDF generation for quotation 2025-12-03 17:00:02 +01:00
sanchezvem d709654410 fix error in GetTotalQuantityEndpoint.cs 2025-11-30 16:59:28 +01:00
sanchezvem 4a82c51133 fixed errors 2025-11-30 15:43:59 +01:00
sanchezvem 8a04adeec3 updated GetSupplierDto.cs 2025-11-30 15:35:08 +01:00
sanchezvem db9219e80f fix error in PatchRealDeliveryDateEndpoint.cs 2025-11-30 14:50:21 +01:00
sanchezvem 9e6834754f added DeleteDeliveryNoteEndpoint.cs 2025-11-30 14:23:30 +01:00
sanchezvem efa7a0be6f added DeleteProductEndpoint.cs 2025-11-29 21:58:20 +01:00
sanchezvem 2a439ccbb5 added mapper 2025-11-28 09:51:12 +01:00
sanchezvem 5c6798a647 fixed errors 2025-11-27 17:24:48 +01:00
Cristiano 50a5f371dd Fixed Database 2025-11-27 14:35:35 +01:00
sanchezvem 86c5d6ae7b new migration 2025-11-27 13:41:55 +01:00
sanchezvem 1c0432a2c4 updated length of password in User.cs 2025-11-27 13:40:02 +01:00
sanchezvem 3e8f36457e fixed errors in database 2025-11-26 20:37:49 +01:00
sanchezvem 5d68ee6992 fix length on approval number 2025-11-26 19:43:54 +01:00
Cristiano d26284d552 Merge branch 'feature/repositories-refactor' into develop 2025-11-20 16:45:55 +01:00
Cristiano d537051bea Fix Type errors 2025-11-20 16:45:44 +01:00
Cristiano 3ad506f869 Retired /api in all the endpoints 2025-11-20 16:33:56 +01:00
Cristiano 9aac7c39f2 Merge branch 'feature/repositories-refactor' into develop
# Conflicts:
#	PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs
#	PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs
#	PyroFetes/Endpoints/Product/GetProductEndpoint.cs
#	PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs
#	PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs
#	PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs
#	PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs
#	PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs
#	PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs
#	PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs
#	PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs
#	PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs
#	PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs
#	PyroFetes/Endpoints/User/GetUserEndpoint.cs
2025-11-20 16:16:15 +01:00
Cristiano b76b668097 Addapted to use cors and optimized connection with the frontend 2025-11-20 16:12:16 +01:00
Cristiano 669938d677 Refactored WarehouseProduct 2025-11-20 16:09:04 +01:00
Cristiano 165c9b9322 Refactored User 2025-11-20 15:38:53 +01:00
Cristiano 0b72549143 Refactored Program.cs 2025-11-20 15:20:13 +01:00
Cristiano d64890dec9 Refactored Supplier 2025-11-20 15:11:14 +01:00
Cristiano 8325aa0768 Refactored Setting 2025-11-20 15:05:44 +01:00
Cristiano ee9b4675dd Refactored Quotation 2025-11-20 14:34:09 +01:00
Cristiano f6383265ba Refactored QuotationProduct 2025-11-20 14:20:25 +01:00
Cristiano 7bf0b5bfd1 Advanced refactoring 2025-11-20 14:04:13 +01:00
Cristiano bd653c149c Finished refactoring prices endpoints 2025-11-19 18:05:28 +01:00
sanchezvem 0511bb5075 added AllowAnonymous(); 2025-11-17 21:25:07 +01:00
sanchezvem 27e8fea7f3 added AllowAnonymous(); 2025-11-17 21:20:04 +01:00
sanchezvem 6dba61f742 suppr all 'var' and Models.xxx. And added 's' at the end of all directories endpoints 2025-11-17 20:49:12 +01:00
Cristiano 20bbccf883 Added last endpoints for delivery Note 2025-11-14 18:11:54 +01:00
Cristiano d7cf245d35 Committed migration 2025-11-13 17:28:41 +01:00
Cristiano 2385b7b687 Made an update on database and added CreatingDeliveryNotee 2025-11-13 17:28:08 +01:00
Cristiano ae834d1e3c Adapted Price Endpoints 2025-11-13 16:31:00 +01:00
Cristiano c6d4ef2c58 Adapted Deliverer endpoints with repository spec and automapper 2025-11-13 15:26:22 +01:00
Cristiano 60a7c059b4 Merge remote-tracking branch 'origin/develop' into develop 2025-11-13 14:44:46 +01:00
Cristiano 9684dbcbc7 Merged AutoMapper branch 2025-11-13 14:44:28 +01:00
253 changed files with 7187 additions and 3242 deletions
@@ -0,0 +1,7 @@
namespace PyroFetes.DTO.Customer.Response;
public class GetCustomerDto
{
public int Id { get; set; }
public string? Note { get; set; }
}
@@ -6,6 +6,6 @@ public class GetDelivererDto
{
public int Id { get; set; }
public string? Transporter { get; set; }
public List<GetDeliveryNoteDto>? DeliveryNotes { get; set; }
}
@@ -3,9 +3,9 @@ namespace PyroFetes.DTO.DeliveryNote.Request;
public class CreateDeliveryNoteDto
{
public string? TrackingNumber { get; set; }
public DateOnly EstimateDeliveryDate { get; set; }
public DateOnly ExpeditionDate { get; set; }
public DateOnly RealDeliveryDate { get; set; }
public int DelivererId { get; set; }
public int SupplierId { get; set; }
public Dictionary<int, int>? ProductQuantities { get; set; }
}
@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.DeliveryNote.Request;
public class GetDeliveryNotePdfDto
{
public int Id { get; set; }
}
@@ -7,6 +7,6 @@ public class UpdateDeliveryNoteDto
public DateOnly EstimateDeliveryDate { get; set; }
public DateOnly ExpeditionDate { get; set; }
public DateOnly? RealDeliveryDate { get; set; }
public int DelivererId { get; set; }
}
@@ -9,9 +9,9 @@ public class GetDeliveryNoteDto
public DateOnly EstimateDeliveryDate { get; set; }
public DateOnly ExpeditionDate { get; set; }
public DateOnly? RealDeliveryDate { get; set; }
public int DelivererId { get; set; }
public string? DelivererTransporter { get; set; }
public List<GetProductDeliveryDto>? Products { get; set; }
public List<GetProductDeliveryDto>? Products { get; set; }
}
+1 -20
View File
@@ -3,25 +3,6 @@
public class CreatePriceDto
{
public decimal SellingPrice { get; set; }
public int? SupplierId { get; set; }
public string? SupplierName { get; set; }
public string? SupplierEmail { get; set; }
public string? SupplierPhone { get; set; }
public string? SupplierAddress { get; set; }
public int SupplierZipCode { get; set; }
public string? SupplierCity { get; set; }
public int SupplierDeliveryDelay { get; set; }
public int? ProductId { get; set; }
public string? 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 ProductId { get; set; }
}
@@ -1,28 +0,0 @@
namespace PyroFetes.DTO.Price.Request;
public class UpdatePriceDto
{
public int Id { get; set; }
public decimal SellingPrice { get; set; }
public int SupplierId { get; set; }
public string? SupplierName { get; set; }
public string? SupplierEmail { get; set; }
public string? SupplierPhone { get; set; }
public string? SupplierAddress { get; set; }
public int SupplierZipCode { get; set; }
public string? SupplierCity { get; set; }
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; }
public string? 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; }
}
+5 -15
View File
@@ -2,24 +2,14 @@
public class GetPriceDto
{
public int Id { get; set; }
public decimal SellingPrice { get; set; }
public int SupplierId { get; set; }
public string? SupplierName { get; set; }
public string? SupplierEmail { get; set; }
public string? SupplierPhone { get; set; }
public string? SupplierAddress { get; set; }
public int SupplierZipCode { get; set; }
public string? SupplierCity { get; set; }
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; }
public string? ProductReferences { get; set; }
public string? ProductReference { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; }
public decimal ProductDuration { get; set; }
public int ProductCaliber { get; set; }
public string? ProductApprovalNumber { get; set; }
public decimal ProductWeight { get; set; }
public decimal ProductNec { get; set; }
public string? ProductImage { get; set; }
@@ -1,15 +0,0 @@
namespace PyroFetes.DTO.Product.Request;
public class CreateProductDto
{
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }
public string? Link { get; set; }
public int MinimalQuantity { get; set; }
}
@@ -5,9 +5,9 @@ public class UpdateProductDto
public int Id { get; set; }
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public decimal Duration { get; set; }
public int Caliber { get; set; }
public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }
@@ -5,9 +5,9 @@ public class GetProductDto
public int Id { get; set; }
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }
public int ApprovalNumber { get; set; }
public decimal Duration { get; set; }
public int Caliber { get; set; }
public string? ApprovalNumber { get; set; }
public decimal Weight { get; set; }
public decimal Nec { get; set; }
public string? Image { get; set; }
@@ -1,8 +0,0 @@
namespace PyroFetes.DTO.ProductDelivery.Request;
public class CreateProductDeliveryDto
{
public int ProductId { get; set; }
public int DeliveryNoteId { get; set; }
public int Quantity { get; set; }
}
@@ -1,8 +0,0 @@
namespace PyroFetes.DTO.ProductDelivery.Request;
public class UpdateProductDeliveryDto
{
public int Quantity { get; set; }
public int ProductId { get; set; }
public int DeliveryNoteId { get; set; }
}
@@ -3,26 +3,16 @@ namespace PyroFetes.DTO.ProductDelivery.Response;
public class GetProductDeliveryDto
{
public int ProductId { get; set; }
public int ProductReference { get; set; }
public string? ProductReference { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; }
public decimal ProductDuration { get; set; }
public int ProductCaliber { get; set; }
public string? 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 DeliveryNoteId { get; set; }
public string? DeliveryNoteTrackingNumber { get; set; }
public DateOnly DeliveryNoteEstimateDeliveryDate { get; set; }
public DateOnly DeliveryNoteExpeditionDate { get; set; }
public DateOnly? DeliveryNoteRealDeliveryDate { get; set; }
public int DeliveryNoteDeliverId { get; set; }
public string? DeliveryNoteDeliverTransporter { get; set; }
public int Quantity { get; set; }
}
@@ -0,0 +1,10 @@
using PyroFetes.DTO.PurchaseProduct.Request;
namespace PyroFetes.DTO.PurchaseOrder.Request;
public class CreatePurchaseOrderDto
{
public string? PurchaseConditions { get; set; }
public int SupplierId { get; set; }
public List<CreatePurchaseOrderProductDto>? Products { get; set; }
}
@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.PurchaseOrder.Request;
public class GetPurchaseOrderPdfDto
{
public int Id { get; set; }
}
@@ -6,5 +6,7 @@ public class GetPurchaseOrderDto
{
public int Id { get; set; }
public string? PurchaseConditions { get; set; }
public List<GetPurchaseProductDto>? GetPurchaseProductDto { get; set; }
public int SupplierId { get; set; }
public string? SupplierName { get; set; }
public List<GetPurchaseProductDto>? Products { get; set; }
}
@@ -0,0 +1,8 @@
namespace PyroFetes.DTO.PurchaseProduct.Request;
// Pour ajouter les produits lors de la création
public class CreatePurchaseOrderProductDto
{
public int ProductId { get; set; }
public int Quantity { get; set; }
}
@@ -2,8 +2,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Request;
public class CreatePurchaseProductDto
{
public int Quantity { get; set; }
public int Quantity { get; set; }
public int ProductId { get; set; }
public int PurchaseOrderId { get; set; }
public string? PurchaseOrderPurchaseConditions { get; set; }
}
@@ -4,5 +4,5 @@ public class PatchPurchaseProductQuantityDto
{
public int ProductId { get; set; }
public int PurchaseOrderId { get; set; }
public int Quantity { get; set; }
public int Quantity { get; set; }
}
@@ -1,22 +0,0 @@
namespace PyroFetes.DTO.PurchaseProduct.Request;
public class UpdatePurchaseProductDto
{
public int ProductId { get; set; }
public int PurchaseOrderId { get; set; }
public int Quantity { 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 string? PurchaseOrderPurchaseConditions { get; set; }
}
@@ -3,19 +3,19 @@ namespace PyroFetes.DTO.PurchaseProduct.Response;
public class GetPurchaseProductDto
{
public int ProductId { get; set; }
public string? ProductReferences { get; set; }
public string? ProductReference { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; }
public decimal ProductDuration { get; set; }
public int ProductCaliber { get; set; }
public string? 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 decimal ProductPrice { get; set; }
public int PurchaseOrderId { get; set; }
public string? PurchaseOrderPurchaseConditions { get; set; }
public int Quantity { get; set; }
}
@@ -0,0 +1,12 @@
using PyroFetes.DTO.QuotationProduct.Request;
namespace PyroFetes.DTO.Quotation.Request;
public class CreateQuotationDto
{
public string? Message { get; set; }
public string? ConditionsSale { get; set; }
public int CustomerId { get; set; }
public int SupplierId { get; set; }
public List<CreateProductQuotationDto>? Products { get; set; }
}
@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.Quotation.Request;
public class GetQuotationPdfDto
{
public int Id { get; set; }
}
@@ -0,0 +1,8 @@
namespace PyroFetes.DTO.Quotation.Request;
public class UpdateQuotationDto
{
public int Id { get; set; }
public string? Message { get; set; }
public string? ConditionsSale { get; set; }
}
@@ -7,5 +7,5 @@ public class GetQuotationDto
public int Id { get; set; }
public string? Message { get; set; }
public string? ConditionsSale { get; set; }
public List<GetQuotationProductDto>? GetQuotationProductDto { get; set; }
public List<GetQuotationProductDto>? Products { get; set; }
}
@@ -0,0 +1,8 @@
namespace PyroFetes.DTO.QuotationProduct.Request;
public class AddQuotationProductDto
{
public int Quantity { get; set; }
public int QuotationId { get; set; }
public int ProductId { get; set; }
}
@@ -0,0 +1,7 @@
namespace PyroFetes.DTO.QuotationProduct.Request;
public class CreateProductQuotationDto
{
public int ProductId { get; set; }
public int Quantity { get; set; }
}
@@ -1,22 +0,0 @@
namespace PyroFetes.DTO.QuotationProduct.Request;
public class CreateQuotationProductDto
{
public int Quantity { get; set; }
public int QuotationId { get; set; }
public string? QuotationMessage { get; set; }
public string? QuotationConditionsSale { 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; }
}
@@ -1,23 +0,0 @@
namespace PyroFetes.DTO.QuotationProduct.Request;
public class UpdateQuotationProductDto
{
public int Id { get; set; }
public int Quantity { get; set; }
public int QuotationId { get; set; }
public string? QuotationMessage { get; set; }
public string? QuotationConditionsSale { 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; }
}
@@ -3,20 +3,18 @@ namespace PyroFetes.DTO.QuotationProduct.Response;
public class GetQuotationProductDto
{
public int Quantity { get; set; }
public int QuotationId { get; set; }
public string? QuotationMessage { get; set; }
public string? QuotationConditionsSale { get; set; }
public int ProductId { get; set; }
public string? ProductReferences { get; set; }
public string? ProductReference { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }
public int ProductApprovalNumber { get; set; }
public decimal ProductDuration { get; set; }
public int ProductCaliber { get; set; }
public string? 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 decimal ProductPrice { get; set; }
public int QuotationId { get; set; }
}
@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.Refresh.Request;
public class RefreshTokenDto
{
public string? Token { get; set; }
}
@@ -0,0 +1,6 @@
namespace PyroFetes.DTO.Refresh.Response;
public class GetRefreshTokenDto
{
public string? Token { get; set; }
}
@@ -2,6 +2,6 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class CreateSettingDto
{
public string? ElectronicSignature { get; set; }
public string? Logo { get; set; }
public IFormFile? ElectronicSignature { get; set; }
public IFormFile? Logo { get; set; }
}
@@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class PatchSettingElectronicSignatureDto
{
public int Id { get; set; }
public string? ElectronicSignature { get; set; }
public IFormFile? ElectronicSignature { get; set; }
}
@@ -2,6 +2,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class PatchSettingLogoDto
{
public int Id { get; set; }
public string? Logo { get; set; }
public IFormFile? Logo { get; set; }
}
@@ -6,7 +6,7 @@ public class CreateSupplierDto
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
public string? City { get; set; }
public int DeliveryDelay { get; set; }
}
@@ -7,7 +7,7 @@ public class UpdateSupplierDto
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
public string? City { get; set; }
public int DeliveryDelay { get; set; }
}
@@ -1,3 +1,5 @@
using PyroFetes.DTO.Price.Response;
namespace PyroFetes.DTO.Supplier.Response;
public class GetSupplierDto
@@ -7,7 +9,8 @@ public class GetSupplierDto
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Address { get; set; }
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
public string? City { get; set; }
public int DeliveryDelay { get; set; }
public List<GetPriceDto>? Prices { get; set; }
}
@@ -5,7 +5,6 @@ public class GetUserDto
public int Id { get; set; }
public string? Name { get; set; }
public string? Password { get; set; }
public string? Salt { get; set; }
public string? Fonction { get; set; }
public string? Email { get; set; }
}
@@ -0,0 +1,7 @@
namespace PyroFetes.DTO.WareHouse.Response;
public class GetWareHouseDto
{
public int Id { get; set; }
public string? Name { get; set; }
}
@@ -0,0 +1,19 @@
using FastEndpoints;
using PyroFetes.DTO.Customer.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Customers;
public class GetAllCustomersEndpoint(CustomersRepository customersRepository, AutoMapper.IMapper mapper) : EndpointWithoutRequest<List<GetCustomerDto>>
{
public override void Configure()
{
Get("/customers");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await customersRepository.ProjectToListAsync<GetCustomerDto>(ct), ct);
}
}
@@ -2,33 +2,26 @@ using FastEndpoints;
using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Deliverers;
public class CreateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<CreateDelivererDto, GetDelivererDto>
public class CreateDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<CreateDelivererDto, GetDelivererDto>
{
public override void Configure()
{
Post("api/deliverers");
AllowAnonymous();
Post("/deliverers");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct)
{
Deliverer newDeliverer = new Deliverer()
Deliverer newDeliverer = new()
{
Transporter = req.Transporter,
};
database.Deliverers.Add(newDeliverer);
await database.SaveChangesAsync(ct);
await Send.OkAsync(new GetDelivererDto()
{
Id = newDeliverer.Id,
Transporter = req.Transporter,
},ct);
await deliverersRepository.AddAsync(newDeliverer, ct);
await Send.NoContentAsync(ct);
}
}
}
@@ -1,6 +1,7 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers;
@@ -8,30 +9,26 @@ public class DeleteDelivererRequest
{
public int DelivererId { get; set; }
}
public class DeleteDelivererEndpoint(PyroFetesDbContext database) : Endpoint<DeleteDelivererRequest>
public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest>
{
public override void Configure()
{
Delete("api/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous();
Delete("/deliverers/{@Id}", x => new { x.DelivererId });
Roles("Admin");
}
public override async Task HandleAsync(DeleteDelivererRequest req, CancellationToken ct)
{
Deliverer? deliverer = await database.Deliverers.SingleOrDefaultAsync(x=>x.Id == req.DelivererId, ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
}
database.Remove(deliverer);
await database.SaveChangesAsync(ct);
await Send.OkAsync(ct);
await deliverersRepository.DeleteAsync(deliverer, ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,29 +1,19 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Scaffolding.Metadata;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Deliverers;
public class GetAllDelivererEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetDelivererDto>>
public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository) : EndpointWithoutRequest<List<GetDelivererDto>>
{
public override void Configure()
{
Get("api/deliverers");
AllowAnonymous();
Get("/deliverers");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetDelivererDto> deliverers = await database.Deliverers.Select(x => new GetDelivererDto()
{
Id = x.Id,
Transporter = x.Transporter,
}).ToListAsync(ct);
await Send.OkAsync(deliverers, ct);
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
}
}
@@ -1,7 +1,8 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers;
@@ -10,30 +11,24 @@ public class GetDelivererRequest
public int DelivererId { get; set; }
}
public class GetDelivererEndpoint(PyroFetesDbContext database) : Endpoint<GetDelivererRequest, GetDelivererDto>
public class GetDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
{
public override void Configure()
{
Get("api/deliverers/{@id}", x=>new {x.DelivererId});
AllowAnonymous();
Get("/deliverers/{@Id}", x => new { x.DelivererId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(GetDelivererRequest req, CancellationToken ct)
{
Deliverer? deliverer = await database.Deliverers.SingleOrDefaultAsync(x=>x.Id == req.DelivererId, ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(new GetDelivererDto()
{
Id = deliverer.Id,
Transporter = deliverer.Transporter,
}, ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
}
}
@@ -1,39 +1,33 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers;
public class UpdateDelivererEndpoint(PyroFetesDbContext database) : Endpoint<UpdateDelivererDto, GetDelivererDto>
public class UpdateDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
{
public override void Configure()
{
Put("api/deliverers/{@id}", x=>new {x.Id});
AllowAnonymous();
Put("/deliverers/{@Id}", x => new { x.Id });
Roles("Admin", "Employe");
}
public override async Task HandleAsync(UpdateDelivererDto req, CancellationToken ct)
{
Deliverer? deliverer = await database.Deliverers.SingleOrDefaultAsync(x=>x.Id == req.Id, ct);
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.Id), ct);
if (deliverer == null)
if (deliverer is null)
{
await Send.NotFoundAsync(ct);
return;
}
deliverer.Transporter = req.Transporter;
await database.SaveChangesAsync(ct);
await Send.OkAsync(new GetDelivererDto()
{
Id = deliverer.Id,
Transporter = deliverer.Transporter,
}, ct);
mapper.Map(req, deliverer);
await deliverersRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,69 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class CreateDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository,
DeliverersRepository deliverersRepository,
ProductsRepository productsRepository,
SuppliersRepository suppliersRepository,
ProductDeliveriesRepository productDeliveriesRepository) : Endpoint<CreateDeliveryNoteDto>
{
public override void Configure()
{
Post("/deliveryNotes");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct)
{
Deliverer? deliverer = await deliverersRepository.SingleOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct);
if (deliverer is null || supplier is null)
{
await Send.NotFoundAsync(ct);
return;
}
//Creating the Delivery Note
DeliveryNote newDeliveryNote = new()
{
TrackingNumber = req.TrackingNumber,
EstimateDeliveryDate = DateOnly.FromDateTime(DateTime.Today).AddMonths(2),
ExpeditionDate = DateOnly.FromDateTime(DateTime.Today),
DelivererId = deliverer.Id,
Deliverer = deliverer,
SupplierId = req.SupplierId,
Supplier = supplier
};
await deliveryNotesRepository.AddAsync(newDeliveryNote, ct);
if (req.ProductQuantities is not null)
{
foreach (KeyValuePair<int, int> productQuantity in req.ProductQuantities)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
if (product is null) continue;
ProductDelivery productDelivery = new()
{
DeliveryNote = newDeliveryNote,
Quantity = productQuantity.Value,
Product = product,
ProductId = product.Id,
DeliveryNoteId = newDeliveryNote.Id
};
await productDeliveriesRepository.AddAsync(productDelivery, ct);
}
}
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class DeleteDeliveryNoteRequest
{
public int Id { get; set; }
}
public class DeleteDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository) : Endpoint<DeleteDeliveryNoteRequest>
{
public override void Configure()
{
Delete("/deliveryNotes/{@Id}", x => new { x.Id });
Roles("Admin");
}
public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct)
{
DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
if (deliveryNote is null)
{
await Send.NotFoundAsync(ct);
return;
}
await deliveryNotesRepository.DeleteAsync(deliveryNote, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,20 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest<List<GetDeliveryNoteDto>>
{
public override void Configure()
{
Get("/deliveryNotes");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync<GetDeliveryNoteDto>(new GetAllDeliveryNoteSpec(), ct), ct);
}
}
@@ -0,0 +1,20 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetAllDeliveryNotesNotArrivedEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest<List<GetDeliveryNoteDto>>
{
public override void Configure()
{
Get("/deliveryNotes/validation");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync<GetDeliveryNoteDto>(new GetAllDeliveryNotesByRealDateSpec(), ct), ct);
}
}
@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetDeliveryNoteRequest
{
public int DeliveryNoteId { get; set; }
}
public class GetDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository,
AutoMapper.IMapper mapper) : Endpoint<GetDeliveryNoteRequest, GetDeliveryNoteDto>
{
public override void Configure()
{
Get("/deliveryNotes/{@Id}", x => new { x.DeliveryNoteId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct)
{
DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct);
if (deliveryNote is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNote), ct);
}
}
@@ -0,0 +1,42 @@
using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Services.Pdf;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetDeliveryNotePdfEndpoint(DeliveryNotesRepository deliveryNotesRepository, IDeliveryNotePdfService deliveryNotePdfService, SettingsRepository settingsRepository)
: Endpoint<GetDeliveryNotePdfDto, byte[]>
{
public override void Configure()
{
Get("/deliveryNotes/{@Id}/pdf", x => new { x.Id });
Roles("Admin","Employe");
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
}
public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct)
{
DeliveryNote? deliveryNote = await deliveryNotesRepository
.SingleOrDefaultAsync(new GetDeliveryNoteByIdWithProductsSpec(req.Id), ct);
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
if (deliveryNote is null)
{
await Send.NotFoundAsync(ct);
return;
}
byte[] bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!, setting!);
await Send.BytesAsync(
bytes: bytes,
contentType: "application/pdf",
fileName: $"bon-de-livraison-{deliveryNote.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct);
}
}
@@ -0,0 +1,41 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class PatchRealDeliveryDateEndpoint(
DeliveryNotesRepository deliveryNotesRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto>
{
public override void Configure()
{
Patch("/deliveryNotes/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct)
{
DeliveryNote? deliveryNoteToPath = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
if (deliveryNoteToPath is null)
{
await Send.NotFoundAsync(ct);
return;
}
if (deliveryNoteToPath.RealDeliveryDate is not null)
{
await Send.StringAsync("Impossible de modifier la date.", 400, cancellation: ct);
return;
}
mapper.Map(req, deliveryNoteToPath);
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,32 @@
using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes;
public class UpdateDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDeliveryNoteDto>
{
public override void Configure()
{
Put("/deliveryNotes/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(UpdateDeliveryNoteDto req, CancellationToken ct)
{
DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
if (deliveryNote is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, deliveryNote);
await deliveryNotesRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,104 +0,0 @@
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<CreatePriceDto, GetPriceDto>
{
public override void Configure()
{
Post("/api/prices");
AllowAnonymous();
}
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
{
// Gestion du fournisseur
var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct);
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);
}
// Gestion du produit
var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct);
if (product == null)
{
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;
}
// Création du prix
var priceAdded = new Models.Price()
{
SellingPrice = req.SellingPrice,
SupplierId = supplier.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 = product.Id,
SupplierName = supplier.Name,
SupplierEmail = supplier.Email,
SupplierPhone = supplier.Phone,
SupplierAddress = supplier.Address,
SupplierCity = supplier.City,
SupplierZipCode = supplier.ZipCode,
SupplierDeliveryDelay = supplier.DeliveryDelay,
ProductReferences = product.Reference,
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
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -1,36 +0,0 @@
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<DeletePriceRequest>
{
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);
}
}
@@ -1,36 +0,0 @@
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<PatchPriceSellingPriceDto, GetPriceDto>
{
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);
}
}
@@ -1,36 +0,0 @@
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<List<GetProductDto>>
{
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);
}
}
@@ -1,48 +0,0 @@
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<GetProductRequest, GetProductDto>
{
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);
}
}
@@ -1,46 +0,0 @@
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<PatchProductMinimalStockDto, GetProductDto>
{
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);
}
}
@@ -1,54 +0,0 @@
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<UpdateProductDto, GetProductDto>
{
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);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products;
public class DeleteProductsRequest
{
public int ProductId { get; set; }
}
public class DeleteProductEndpoint(ProductsRepository productsRepository) : Endpoint<DeleteProductsRequest>
{
public override void Configure()
{
Delete("/products/{@Id}", x => new { x.ProductId });
Roles("Admin");
}
public override async Task HandleAsync(DeleteProductsRequest req, CancellationToken ct)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
await productsRepository.DeleteAsync(product, ct);
await Send.OkAsync(ct);
}
}
@@ -0,0 +1,19 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Products;
public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
{
public override void Configure()
{
Get("/products");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(ct), ct);
}
}
@@ -0,0 +1,20 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products;
public class GetAllProductsUnderLimitEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest<List<GetProductDto>>
{
public override void Configure()
{
Get("/products/underLimit");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await productsRepository.ProjectToListAsync<GetProductDto>(new GetProductsUnderLimitSpec(), ct), ct);
}
}
@@ -0,0 +1,37 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products;
public class GetProductRequest
{
public int Id { get; set; }
}
public class GetProductEndpoint(
ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<GetProductRequest, GetProductDto>
{
public override void Configure()
{
Get("/products/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
{
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
}
}
@@ -0,0 +1,32 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products;
public class PatchProductMinimalStockEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto>
{
public override void Configure()
{
Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, product);
await productsRepository.UpdateAsync(product, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,32 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products;
public class UpdateProductEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto>
{
public override void Configure()
{
Put("/products/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, product);
await productsRepository.UpdateAsync(product, ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,41 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.PurchaseOrder;
public class DeletePurchaseOrderRequest
{
public int Id { get; set; }
}
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseOrderRequest>
{
public override void Configure()
{
Delete("/api/purchaseOrders/{@Id}", x => new {x.Id});
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);
}
}
@@ -1,45 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseOrder;
public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
{
public override void Configure()
{
Get("/api/purchaseOrders");
}
public override async Task HandleAsync(CancellationToken ct)
{
var purchaseOrder = await database.PurchaseOrders
.Include(p => p.PurchaseProducts)
.Select(purchaseOrder => new GetPurchaseOrderDto()
{
Id = purchaseOrder.Id,
PurchaseConditions = purchaseOrder.PurchaseConditions,
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
.Select(p => new GetPurchaseProductDto
{
ProductId = p.ProductId,
ProductReferences = p.Product.Reference,
ProductName = p.Product.Name,
ProductDuration = p.Product.Duration,
ProductCaliber = p.Product.Caliber,
ProductApprovalNumber = p.Product.ApprovalNumber,
ProductWeight = p.Product.Weight,
ProductNec = p.Product.Nec,
ProductImage = p.Product.Image,
ProductLink = p.Product.Link,
ProductMinimalQuantity = p.Product.MinimalQuantity,
PurchaseOrderId = p.PurchaseOrderId,
Quantity = p.Quantity,
}).ToList()
})
.ToListAsync(ct);
await Send.OkAsync(purchaseOrder, ct);
}
}
@@ -1,56 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseOrder;
public class GetPurchaseOrderRequest
{
public int Id { get; set; }
}
public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
{
public override void Configure()
{
Get("/api/purchaseOrders/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
{
var purchaseOrder = await database.PurchaseOrders
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (purchaseOrder == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetPurchaseOrderDto responseDto = new()
{
Id = purchaseOrder.Id,
PurchaseConditions = purchaseOrder.PurchaseConditions,
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
.Select(p => new GetPurchaseProductDto
{
ProductId = p.ProductId,
ProductReferences = p.Product.Reference,
ProductName = p.Product.Name,
ProductDuration = p.Product.Duration,
ProductCaliber = p.Product.Caliber,
ProductApprovalNumber = p.Product.ApprovalNumber,
ProductWeight = p.Product.Weight,
ProductNec = p.Product.Nec,
ProductImage = p.Product.Image,
ProductLink = p.Product.Link,
ProductMinimalQuantity = p.Product.MinimalQuantity,
PurchaseOrderId = p.PurchaseOrderId,
Quantity = p.Quantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -1,54 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseOrder;
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
{
public override void Configure()
{
Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
{
var purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct);
if (purchaseOrder == null)
{
await Send.NotFoundAsync(ct);
return;
}
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
await database.SaveChangesAsync(ct);
GetPurchaseOrderDto responseDto = new()
{
Id = purchaseOrder.Id,
PurchaseConditions = purchaseOrder.PurchaseConditions,
GetPurchaseProductDto = purchaseOrder.PurchaseProducts
.Select(p => new GetPurchaseProductDto
{
ProductId = p.ProductId,
ProductReferences = p.Product.Reference,
ProductName = p.Product.Name,
ProductDuration = p.Product.Duration,
ProductCaliber = p.Product.Caliber,
ProductApprovalNumber = p.Product.ApprovalNumber,
ProductWeight = p.Product.Weight,
ProductNec = p.Product.Nec,
ProductImage = p.Product.Image,
ProductLink = p.Product.Link,
ProductMinimalQuantity = p.Product.MinimalQuantity,
PurchaseOrderId = p.PurchaseOrderId,
Quantity = p.Quantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -0,0 +1,32 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class AddProductFromPurchaseOrderEndpoint(PurchaseProductsRepository purchaseProductsRepository, AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseProductDto>
{
public override void Configure()
{
Post("/purchaseOrders/{@PurchaseOrderId}/{@ProductId}", x => new { x.PurchaseOrderId, x.ProductId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
{
PurchaseProduct? purchaseOrderProduct =
await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
if (purchaseOrderProduct is not null)
{
await Send.StringAsync("Le produit est déjà dans le bon de commande", 400, cancellation: ct);
return;
}
purchaseOrderProduct = mapper.Map<PurchaseProduct>(req);
await purchaseProductsRepository.AddAsync(purchaseOrderProduct, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,57 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class CreatePurchaseOrder(
PurchaseOrdersRepository purchaseOrdersRepository,
ProductsRepository productsRepository,
PurchaseProductsRepository purchaseProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseOrderDto, GetPurchaseOrderDto>
{
public override void Configure()
{
Post("/purchaseOrders");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct)
{
PurchaseOrder purchaseOrder = mapper.Map<PurchaseOrder>(req);
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
if (req.Products != null)
{
foreach (CreatePurchaseOrderProductDto line in req.Products)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(line.ProductId), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
PurchaseProduct? purchaseProduct =
await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(line.ProductId, purchaseOrder.Id), ct);
if (purchaseProduct is not null)
{
await Send.StringAsync("Le produit est déjà dans le bon de commande", 400, cancellation: ct);
return;
}
PurchaseProduct? productOnPurchase = mapper.Map<PurchaseProduct>(line);
productOnPurchase.PurchaseOrderId = purchaseOrder.Id;
await purchaseProductsRepository.AddAsync(productOnPurchase, ct);
}
}
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
}
}
@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class DeletePurchaseProductRequest
{
public int ProductId { get; set; }
public int PurchaseOrderId { get; set; }
}
public class DeleteProductFromPurchaseOrderEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest>
{
public override void Configure()
{
Delete("/purchaseOrders/{@ProductId}/{@PurchaseOrderId}", x => new { x.ProductId, x.PurchaseOrderId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
{
PurchaseProduct? purchaseProduct =
await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
if (purchaseProduct is null)
{
await Send.NotFoundAsync(ct);
return;
}
await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class DeletePurchaseOrderRequest
{
public int Id { get; set; }
}
public class DeletePurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : Endpoint<DeletePurchaseOrderRequest>
{
public override void Configure()
{
Delete("/purchaseOrders/{@Id}", x => new { x.Id });
Roles("Admin");
}
public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct)
{
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
if (purchaseOrder is null)
{
await Send.NotFoundAsync(ct);
return;
}
await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,20 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : EndpointWithoutRequest<List<GetPurchaseOrderDto>>
{
public override void Configure()
{
Get("/purchaseOrders");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync<GetPurchaseOrderDto>(new GetAllPurchaseOrderSpec(), ct), ct);
}
}
@@ -0,0 +1,34 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class GetPurchaseOrderRequest
{
public int Id { get; set; }
}
public class GetPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
{
public override void Configure()
{
Get("/purchaseOrders/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
{
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
if (purchaseOrder is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
}
}
@@ -0,0 +1,44 @@
using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Services.Pdf;
using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class GetPurchaseOrderPdfEndpoint(
PurchaseOrdersRepository purchaseOrdersRepository,
IPurchaseOrderPdfService purchaseOrderPdfService,
SettingsRepository settingsRepository)
: Endpoint<GetPurchaseOrderPdfDto, byte[]>
{
public override void Configure()
{
Get("/purchaseOrders/{@Id}/pdf", x => new { x.Id });
Roles("Admin","Employe");
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
}
public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct)
{
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdWithProductsSpec(req.Id), ct);
if (purchaseOrder is null)
{
await Send.NotFoundAsync(ct);
return;
}
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
byte[] bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!, setting!);
await Send.BytesAsync(
bytes: bytes,
contentType: "application/pdf",
fileName: $"bon-de-commande-{purchaseOrder.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct);
}
}
@@ -0,0 +1,33 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper)
: Endpoint<PatchPurchaseOrderPurchaseConditionsDto>
{
public override void Configure()
{
Patch("/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
{
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
if (purchaseOrder is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, purchaseOrder);
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseOrders;
public class PatchPurchaseProductQuantityEndpoint(PurchaseProductsRepository purchaseProductsRepository, AutoMapper.IMapper mapper)
: Endpoint<PatchPurchaseProductQuantityDto>
{
public override void Configure()
{
Patch("/purchaseOrders/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
{
PurchaseProduct? purchaseProduct =
await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
if (purchaseProduct is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, purchaseProduct);
await purchaseProductsRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,67 +0,0 @@
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<CreatePurchaseProductDto, GetPurchaseProductDto>
{
public override void Configure()
{
Post("/api/purchaseProducts");
AllowAnonymous();
}
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
{
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
if (product == null)
{
await Send.NotFoundAsync(ct);
return;
}
var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct);
if (purchaseOrder == null)
{
purchaseOrder = new Models.PurchaseOrder()
{
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
};
database.PurchaseOrders.Add(purchaseOrder);
await database.SaveChangesAsync(ct);
}
var purchaseProduct = new Models.PurchaseProduct()
{
ProductId = product.Id,
PurchaseOrderId = purchaseOrder.Id,
Quantity = req.Quantity
};
database.PurchaseProducts.Add(purchaseProduct);
await database.SaveChangesAsync(ct);
var responseDto = new GetPurchaseProductDto()
{
ProductId = product.Id,
ProductReferences = product.Reference,
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);
}
}
@@ -1,36 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.PurchaseProduct;
public class DeletePurchaseProductRequest
{
public int ProductId { get; set; }
public int PurchaseOrderId { get; set; }
}
public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint<DeletePurchaseProductRequest>
{
public override void Configure()
{
Delete("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
AllowAnonymous();
}
public override async Task HandleAsync(DeletePurchaseProductRequest 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;
}
database.PurchaseProducts.Remove(purchaseProduct);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,36 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.PurchaseProduct.Response;
namespace PyroFetes.Endpoints.PurchaseProduct;
public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
{
public override void Configure()
{
Patch("/api/purchaseProducts/{@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);
}
}
@@ -1,41 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Quotation;
public class DeleteQuotationRequest
{
public int Id { get; set; }
}
public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationRequest>
{
public override void Configure()
{
Delete("/api/quotations/{@Id}", x => new {x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
{
var quotation = await database.Quotations
.Include(q => q.QuotationProducts)
.SingleOrDefaultAsync(q => q.Id == req.Id, ct);
if (quotation == null)
{
await Send.NotFoundAsync(ct);
return;
}
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
{
database.QuotationProducts.RemoveRange(quotation.QuotationProducts);
}
database.Quotations.Remove(quotation);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,48 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.Quotation;
public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetQuotationDto>>
{
public override void Configure()
{
Get("/api/quotations");
}
public override async Task HandleAsync(CancellationToken ct)
{
var quotations = await database.Quotations
.Include(q => q.QuotationProducts!)
.ThenInclude(qp => qp.Product)
.Select(q => new GetQuotationDto
{
Id = q.Id,
Message = q.Message,
ConditionsSale = q.ConditionsSale,
GetQuotationProductDto = q.QuotationProducts.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = q.Id,
QuotationMessage = q.Message,
QuotationConditionsSale = q.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
})
.ToListAsync(ct);
await Send.OkAsync(quotations, ct);
}
}
@@ -1,59 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.Quotation;
public class GetQuotationRequest
{
public int Id { get; set; }
}
public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint<GetQuotationRequest, GetQuotationDto>
{
public override void Configure()
{
Get("/api/quotations/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
{
var quotation = await database.Quotations
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (quotation == null)
{
await Send.NotFoundAsync(ct);
return;
}
GetQuotationDto responseDto = new()
{
Id = quotation.Id,
Message = quotation.Message,
ConditionsSale = quotation.ConditionsSale,
GetQuotationProductDto = quotation.QuotationProducts
.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = quotation.Id,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -1,58 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.Quotation;
public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
{
public override void Configure()
{
Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
{
var quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (quotation == null)
{
await Send.NotFoundAsync(ct);
return;
}
quotation.ConditionsSale = req.ConditionsSale;
await database.SaveChangesAsync(ct);
GetQuotationDto responseDto = new()
{
Id = quotation.Id,
Message = quotation.Message,
ConditionsSale = quotation.ConditionsSale,
GetQuotationProductDto = quotation.QuotationProducts.Select(qp => new GetQuotationProductDto
{
Quantity = qp.Quantity,
QuotationId = quotation.Id,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
ProductId = qp.ProductId,
ProductReferences = qp.Product.Reference,
ProductName = qp.Product.Name,
ProductDuration = qp.Product.Duration,
ProductCaliber = qp.Product.Caliber,
ProductApprovalNumber = qp.Product.ApprovalNumber,
ProductWeight = qp.Product.Weight,
ProductNec = qp.Product.Nec,
ProductImage = qp.Product.Image,
ProductLink = qp.Product.Link,
ProductMinimalQuantity = qp.Product.MinimalQuantity,
}).ToList()
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -1,68 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.QuotationProduct;
public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
{
public override void Configure()
{
Post("/api/quotationProduct");
AllowAnonymous();
}
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
{
var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct);
if (product == null)
{
await Send.NotFoundAsync(ct);
return;
}
var quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct);
if (quotation == null)
{
quotation = new Models.Quotation()
{
Message = req.QuotationMessage ?? "",
ConditionsSale = req.QuotationConditionsSale,
};
database.Quotations.Add(quotation);
await database.SaveChangesAsync(ct);
}
var quotationProduct = new Models.QuotationProduct()
{
ProductId = product.Id,
QuotationId = quotation.Id,
Quantity = req.Quantity
};
database.QuotationProducts.Add(quotationProduct);
await database.SaveChangesAsync(ct);
var responseDto = new GetQuotationProductDto()
{
ProductId = product.Id,
ProductReferences = product.Reference,
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,
Quantity = quotationProduct.Quantity,
QuotationMessage = quotation.Message,
QuotationConditionsSale = quotation.ConditionsSale,
QuotationId = quotation.Id,
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -1,36 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.QuotationProduct;
public class DeleteQuotationProductRequest
{
public int ProductId { get; set; }
public int QuotationId { get; set; }
}
public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint<DeleteQuotationProductRequest>
{
public override void Configure()
{
Delete("/api/quotationProduct/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
AllowAnonymous();
}
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
{
var quotationProduct = await database.QuotationProducts
.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
if (quotationProduct == null)
{
await Send.NotFoundAsync(ct);
return;
}
database.QuotationProducts.Remove(quotationProduct);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}
@@ -1,36 +0,0 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
namespace PyroFetes.Endpoints.QuotationProduct;
public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
{
public override void Configure()
{
Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous();
}
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
{
var quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct);
if (quotationProduct == null)
{
await Send.NotFoundAsync(ct);
return;
}
quotationProduct.Quantity = req.Quantity;
await database.SaveChangesAsync(ct);
GetQuotationProductDto responseDto = new()
{
ProductId = quotationProduct.ProductId,
QuotationId = quotationProduct.QuotationId,
Quantity = quotationProduct.Quantity
};
await Send.OkAsync(responseDto, ct);
}
}
@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.Quotations;
public class AddProductoToQuotationEndpoint(
QuotationProductsRepository quotationProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<AddQuotationProductDto>
{
public override void Configure()
{
Post("/quotations/{@Id}/products", x => new { x.ProductId, x.QuotationId });
Roles("Admin","Employe");
}
public override async Task HandleAsync(AddQuotationProductDto req, CancellationToken ct)
{
QuotationProduct? productQuotation =
await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
if (productQuotation is not null)
{
await Send.StringAsync("ce produit existe déjà dans le devis", 400, cancellation: ct);
return;
}
QuotationProduct quotationProduct = mapper.Map<QuotationProduct>(req);
await quotationProductsRepository.AddAsync(quotationProduct, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,57 @@
using FastEndpoints;
using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.Quotations;
public class CreateQuotationEndpoint(
QuotationsRepository quotationsRepository,
QuotationProductsRepository quotationProductsRepository,
ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationDto>
{
public override void Configure()
{
Post("/quotations");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CreateQuotationDto req, CancellationToken ct)
{
Quotation quotation = mapper.Map<Quotation>(req);
await quotationsRepository.AddAsync(quotation, ct);
if (req.Products != null)
{
foreach (CreateProductQuotationDto line in req.Products)
{
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(line.ProductId), ct);
QuotationProduct? quotationProduct =
await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(line.ProductId, quotation.Id), ct);
if (product is null)
{
await Send.NotFoundAsync(ct);
return;
}
if (quotationProduct is not null)
{
await Send.StringAsync("Le produit est déjà dans le devis", 400, cancellation: ct);
return;
}
QuotationProduct? productOnQuotation = mapper.Map<QuotationProduct>(line);
productOnQuotation.QuotationId = quotation.Id;
await quotationProductsRepository.AddAsync(productOnQuotation, ct);
}
}
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.Quotations;
public class DeleteQuotationProductRequest
{
public int ProductId { get; set; }
public int QuotationId { get; set; }
}
public class DeleteProductFromQuotationEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
{
public override void Configure()
{
Delete("/quotations/{@ProductId}/{@QuotationId}", x => new { x.ProductId, x.QuotationId });
Roles("Admin", "Employe");
}
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
{
QuotationProduct? quotationProduct =
await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
if (quotationProduct is null)
{
await Send.NotFoundAsync(ct);
return;
}
await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class DeleteQuotationRequest
{
public int Id { get; set; }
}
public class DeleteQuotationEndpoint(QuotationsRepository quotationsRepository) : Endpoint<DeleteQuotationRequest>
{
public override void Configure()
{
Delete("/quotations/{@Id}", x => new { x.Id });
Roles("Admin");
}
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation is null)
{
await Send.NotFoundAsync(ct);
return;
}
await quotationsRepository.DeleteAsync(quotation, ct);
await Send.NoContentAsync(ct);
}
}
@@ -0,0 +1,20 @@
using FastEndpoints;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository) : EndpointWithoutRequest<List<GetQuotationDto>>
{
public override void Configure()
{
Get("/quotations");
Roles("Admin","Employe");
}
public override async Task HandleAsync(CancellationToken ct)
{
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(new GetAllQuotationSpec(), ct), ct);
}
}
@@ -0,0 +1,36 @@
using FastEndpoints;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class GetQuotationRequest
{
public int Id { get; set; }
}
public class GetQuotationEndpoint(
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<GetQuotationRequest, GetQuotationDto>
{
public override void Configure()
{
Get("/quotations/{@Id}", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
{
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation is null)
{
await Send.NotFoundAsync(ct);
return;
}
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
}
}
@@ -0,0 +1,44 @@
using System.Net.Mime;
using FastEndpoints;
using PyroFetes.DTO.Quotation.Request;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Services.Pdf;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class GetQuotationPdfEndpoint(
QuotationsRepository quotationRepository,
IQuotationPdfService quotationPdfService,
SettingsRepository settingsRepository)
: Endpoint<GetQuotationPdfDto, byte[]>
{
public override void Configure()
{
Get("/quotations/{@Id}/pdf", x => new { x.Id });
Roles("Admin","Employe");
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
}
public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct)
{
Quotation? quotation = await quotationRepository.SingleOrDefaultAsync(new GetQuotationByIdWithProductsSpec(req.Id), ct);
if (quotation is null)
{
await Send.NotFoundAsync(ct);
return;
}
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
byte[] bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!, setting!);
await Send.BytesAsync(
bytes: bytes,
contentType: "application/pdf",
fileName: $"devis-{quotation.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct);
}
}
@@ -0,0 +1,35 @@
using FastEndpoints;
using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response;
using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.Quotations;
public class PatchQuotationConditionsSaleEndpoint(
QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto>
{
public override void Configure()
{
Patch("/quotations/{@Id}/saleConditions", x => new { x.Id });
Roles("Admin","Employe");
}
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
{
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
if (quotation is null)
{
await Send.NotFoundAsync(ct);
return;
}
mapper.Map(req, quotation);
await quotationsRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

Some files were not shown because too many files have changed in this diff Show More