Compare commits
60 Commits
7f3ffde3ff
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 09ce53203c | |||
| d17f2fb23e | |||
| 3065bba7fb | |||
| 697e1431d9 | |||
| de6a1c5385 | |||
| 29759cf896 | |||
| da1407579d | |||
| 602b91006e | |||
| f0ad9b536a | |||
| fb97729c71 | |||
| 1bd92a8732 | |||
| 8c38255ed9 | |||
| 639631a63b | |||
| 5869ae18c4 | |||
| fc9da89ebe | |||
| 76239b41bd | |||
| 88882f9db8 | |||
| 6339fbdb8c | |||
| 6f2c60e6c0 | |||
| cac880e35f | |||
| 897b036fc5 | |||
| 19c63ef317 | |||
| fdaead91ff | |||
| aa40ae2e7a | |||
| ed59efe4f8 | |||
| b13b8ebfb6 | |||
| 57646a1417 | |||
| 3cb619cfa6 | |||
| 48b9db6e1c | |||
| c0ac9f7a65 | |||
| d46fa606b7 | |||
| b59a8b6c3d | |||
| 1ae8072219 | |||
| 1434a5d77a | |||
| 656100d15e | |||
| fe58e5e7e7 | |||
| 9c723a7a10 | |||
| 0312f02028 | |||
| 418c2b3d16 | |||
| 3487baad87 | |||
| 29e2036965 | |||
| be7a3193ab | |||
| 0802ec9e33 | |||
| 35d3e58d86 | |||
| 2a42e1010f | |||
| 2fa74ccba8 | |||
| 65cff130e4 | |||
| e21e2afea4 | |||
| 17978e7c19 | |||
| 6a20676b32 | |||
| e440dcd2b5 | |||
| bee1cfb0e3 | |||
| d709654410 | |||
| 4a82c51133 | |||
| 8a04adeec3 | |||
| db9219e80f | |||
| 9e6834754f | |||
| efa7a0be6f | |||
| 2a439ccbb5 | |||
| 5c6798a647 |
@@ -0,0 +1,7 @@
|
||||
namespace PyroFetes.DTO.Customer.Response;
|
||||
|
||||
public class GetCustomerDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string? Note { get; set; }
|
||||
}
|
||||
@@ -3,10 +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 int DelivererId { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
|
||||
public Dictionary<int,int>? ProductQuantities { 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; }
|
||||
}
|
||||
@@ -13,5 +13,5 @@ public class GetDeliveryNoteDto
|
||||
public int DelivererId { get; set; }
|
||||
public string? DelivererTransporter { get; set; }
|
||||
|
||||
public List<GetProductDeliveryDto>? Products { get; set; }
|
||||
public List<GetProductDeliveryDto>? Products { get; set; }
|
||||
}
|
||||
@@ -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 string? 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 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 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; }
|
||||
}
|
||||
@@ -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 int Caliber { get; set; }
|
||||
public string? 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,7 +5,7 @@ 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 Duration { get; set; }
|
||||
public int Caliber { get; set; }
|
||||
public string? ApprovalNumber { get; set; }
|
||||
public decimal Weight { get; set; }
|
||||
|
||||
@@ -5,7 +5,7 @@ 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 Duration { get; set; }
|
||||
public int Caliber { get; set; }
|
||||
public string? ApprovalNumber { get; set; }
|
||||
public decimal Weight { 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; }
|
||||
}
|
||||
@@ -5,5 +5,4 @@ public class CreatePurchaseProductDto
|
||||
public int Quantity { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
public string? PurchaseOrderPurchaseConditions { 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; }
|
||||
}
|
||||
@@ -4,19 +4,17 @@ 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; }
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
|
||||
namespace PyroFetes.DTO.Supplier.Response;
|
||||
|
||||
public class GetSupplierDto
|
||||
@@ -10,4 +12,5 @@ public class GetSupplierDto
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -6,25 +6,22 @@ using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
public class CreateDelivererEndpoint(
|
||||
DeliverersRepository deliverersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||
public class CreateDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<CreateDelivererDto, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/deliverers");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct)
|
||||
{
|
||||
Deliverer newDeliverer = new Deliverer()
|
||||
Deliverer newDeliverer = new()
|
||||
{
|
||||
Transporter = req.Transporter,
|
||||
};
|
||||
|
||||
await deliverersRepository.AddAsync(newDeliverer, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -9,28 +9,26 @@ public class DeleteDelivererRequest
|
||||
{
|
||||
public int DelivererId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/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 deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(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 deliverersRepository.DeleteAsync(deliverer, ct);
|
||||
|
||||
await Send.OkAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
@@ -11,13 +9,11 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/deliverers");
|
||||
AllowAnonymous();
|
||||
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
@@ -12,22 +11,19 @@ public class GetDelivererRequest
|
||||
public int DelivererId { get; set; }
|
||||
}
|
||||
|
||||
public class GetDelivererEndpoint(
|
||||
DeliverersRepository deliverersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||
public class GetDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/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 deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(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;
|
||||
@@ -35,5 +31,4 @@ public class GetDelivererEndpoint(
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Deliverer.Request;
|
||||
using PyroFetes.DTO.Deliverer.Response;
|
||||
using PyroFetes.Models;
|
||||
@@ -8,32 +7,27 @@ using PyroFetes.Specifications.Deliverers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Deliverers;
|
||||
|
||||
public class UpdateDelivererEndpoint(
|
||||
DeliverersRepository deliverersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||
public class UpdateDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/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 deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(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;
|
||||
mapper.Map(req, deliverer);
|
||||
|
||||
await deliverersRepository.UpdateAsync(deliverer,ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
|
||||
await deliverersRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Request;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Deliverers;
|
||||
using PyroFetes.Specifications.Products;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
@@ -12,57 +12,58 @@ public class CreateDeliveryNoteEndpoint(
|
||||
DeliveryNotesRepository deliveryNotesRepository,
|
||||
DeliverersRepository deliverersRepository,
|
||||
ProductsRepository productsRepository,
|
||||
ProductDeliveriesRepository productDeliveriesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateDeliveryNoteDto, GetDeliveryNoteDto>
|
||||
SuppliersRepository suppliersRepository,
|
||||
ProductDeliveriesRepository productDeliveriesRepository) : Endpoint<CreateDeliveryNoteDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/deliveryNotes");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct)
|
||||
{
|
||||
Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct);
|
||||
|
||||
if (deliverer == null)
|
||||
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.StringAsync("No deliverer found", 404, cancellation: ct);
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
//Creating the Delivery Note
|
||||
DeliveryNote newDeliveryNote = new DeliveryNote()
|
||||
DeliveryNote newDeliveryNote = new()
|
||||
{
|
||||
TrackingNumber = req.TrackingNumber,
|
||||
EstimateDeliveryDate = req.EstimateDeliveryDate,
|
||||
ExpeditionDate = req.ExpeditionDate,
|
||||
DelivererId = req.DelivererId,
|
||||
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);
|
||||
|
||||
foreach (var productQuantity in req.ProductQuantities!)
|
||||
if (req.ProductQuantities is not null)
|
||||
{
|
||||
Product? product =
|
||||
await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
|
||||
if (product != null)
|
||||
foreach (KeyValuePair<int, int> productQuantity in req.ProductQuantities)
|
||||
{
|
||||
ProductDelivery productDelivery = new ProductDelivery()
|
||||
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.OkAsync(mapper.Map<GetDeliveryNoteDto>(newDeliveryNote), 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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.DeliveryNotes;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
@@ -9,12 +10,11 @@ public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRep
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/deliveryNotes");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync<GetDeliveryNoteDto>(ct), 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);
|
||||
}
|
||||
}
|
||||
@@ -10,21 +10,22 @@ 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});
|
||||
AllowAnonymous();
|
||||
Get("/deliveryNotes/{@Id}", x => new { x.DeliveryNoteId });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct)
|
||||
{
|
||||
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct);
|
||||
DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct);
|
||||
|
||||
if (deliveryNote == null)
|
||||
if (deliveryNote is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +1,41 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.DeliveryNote.Request;
|
||||
using PyroFetes.DTO.DeliveryNote.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Deliverers;
|
||||
using PyroFetes.Specifications.DeliveryNotes;
|
||||
|
||||
namespace PyroFetes.Endpoints.DeliveryNotes;
|
||||
|
||||
public class PatchRealDeliveryDateEndpoint(
|
||||
DeliveryNotesRepository deliveryNotesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto, GetDeliveryNoteDto>
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/deliveryNotes/{@id}", x=> new {x.Id});
|
||||
AllowAnonymous();
|
||||
Patch("/deliveryNotes/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct)
|
||||
{
|
||||
DeliveryNote? deliveryNoteToPath =
|
||||
await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id),ct);
|
||||
DeliveryNote? deliveryNoteToPath = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
|
||||
|
||||
if (deliveryNoteToPath == null)
|
||||
if (deliveryNoteToPath is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate;
|
||||
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.OkAsync(mapper.Map<GetDeliveryNoteDto>(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,84 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
using PyroFetes.Specifications.Products;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Prices;
|
||||
|
||||
public class CreatePriceEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
ProductsRepository productsRepository,
|
||||
PricesRepository pricesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreatePriceDto, GetPriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/prices");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
|
||||
{
|
||||
// Gestion du fournisseur
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct);
|
||||
if (supplier == null)
|
||||
{
|
||||
supplier = new Supplier()
|
||||
{
|
||||
Name = req.SupplierName,
|
||||
Email = req.SupplierEmail,
|
||||
Phone = req.SupplierPhone,
|
||||
Address = req.SupplierAddress,
|
||||
City = req.SupplierCity,
|
||||
ZipCode = req.SupplierZipCode,
|
||||
DeliveryDelay = req.SupplierDeliveryDelay
|
||||
};
|
||||
await suppliersRepository.AddAsync(supplier, ct);
|
||||
}
|
||||
|
||||
// Gestion du produit
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
if (product == null)
|
||||
{
|
||||
product = new 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
|
||||
};
|
||||
await productsRepository.AddAsync(product, ct);
|
||||
}
|
||||
|
||||
// Vérifie si le prix existe déjà pour ce fournisseur et produit
|
||||
Price? existingPrice = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct);
|
||||
|
||||
if (existingPrice != null)
|
||||
{
|
||||
await Send.StringAsync("Le fournisseur a déjà un prix pour ce produit.", 400, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// Création du prix
|
||||
var priceAdded = new Price()
|
||||
{
|
||||
SellingPrice = req.SellingPrice,
|
||||
SupplierId = supplier.Id,
|
||||
ProductId = product.Id
|
||||
};
|
||||
await pricesRepository.AddAsync(priceAdded, ct);
|
||||
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPriceDto>(priceAdded), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
|
||||
namespace PyroFetes.Endpoints.Prices;
|
||||
|
||||
public class DeletePriceRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
|
||||
{
|
||||
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId,req.SupplierId), ct);
|
||||
|
||||
if (price == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await pricesRepository.DeleteAsync(price, ct);
|
||||
|
||||
await Send.NoContentAsync(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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Products;
|
||||
@@ -11,7 +9,7 @@ public class GetAllProductsEndpoint(ProductsRepository productsRepository) : End
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/products");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken 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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
@@ -18,20 +17,21 @@ public class GetProductEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/products/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
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 == null)
|
||||
if (product is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,32 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Request;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Products;
|
||||
|
||||
namespace PyroFetes.Endpoints.Products;
|
||||
|
||||
public class PatchProductMinimalStockEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto, GetProductDto>
|
||||
public class PatchProductMinimalStockEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/products/{@Id}/MinimalStock", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
|
||||
if (product == null)
|
||||
if (product is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
product.MinimalQuantity = req.MinimalQuantity;
|
||||
await productsRepository.UpdateAsync(product, ct);
|
||||
mapper.Map(req, product);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
await productsRepository.UpdateAsync(product, ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +1,32 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Product.Request;
|
||||
using PyroFetes.DTO.Product.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Products;
|
||||
|
||||
namespace PyroFetes.Endpoints.Products;
|
||||
|
||||
public class UpdateProductEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto, GetProductDto>
|
||||
public class UpdateProductEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/products/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Put("/products/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
|
||||
|
||||
if (product == null)
|
||||
if (product is 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;
|
||||
mapper.Map(req, product);
|
||||
|
||||
await productsRepository.UpdateAsync(product, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct);
|
||||
await Send.NoContentAsync(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);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
@@ -11,33 +10,26 @@ public class DeletePurchaseOrderRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseOrderEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseOrderRequest>
|
||||
public class DeletePurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : Endpoint<DeletePurchaseOrderRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
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 == null)
|
||||
if (purchaseOrder is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
|
||||
{
|
||||
await purchaseProductsRepository.DeleteRangeAsync(purchaseOrder.PurchaseProducts, ct);
|
||||
}
|
||||
|
||||
await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseOrders;
|
||||
|
||||
@@ -11,11 +10,11 @@ public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrders
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/purchaseOrders");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync<GetPurchaseOrderDto>(ct), ct);
|
||||
await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync<GetPurchaseOrderDto>(new GetAllPurchaseOrderSpec(), ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
@@ -13,21 +11,19 @@ public class GetPurchaseOrderRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetPurchaseOrderEndpoint(
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
public class GetPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/purchaseOrders/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Get("/purchaseOrders/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
if (purchaseOrder is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,33 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||
using PyroFetes.DTO.PurchaseProduct.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, GetPurchaseOrderDto>
|
||||
public class PatchPurchaseOrderPurchaseConditionsEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper)
|
||||
: Endpoint<PatchPurchaseOrderPurchaseConditionsDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct)
|
||||
{
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
if (purchaseOrder == null)
|
||||
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
|
||||
if (purchaseOrder is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseOrder.PurchaseConditions = req.PurchaseConditions;
|
||||
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
|
||||
mapper.Map(req, purchaseOrder);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||
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,56 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Products;
|
||||
using PyroFetes.Specifications.PurchaseOrders;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||
|
||||
public class CreatePurchaseProductEndpoint(
|
||||
ProductsRepository productsRepository,
|
||||
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||
PurchaseProductsRepository purchaseProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseProductDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/purchaseProducts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
PurchaseOrder? purchaseOrder =
|
||||
await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseOrder == null)
|
||||
{
|
||||
purchaseOrder = new PurchaseOrder()
|
||||
{
|
||||
PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées"
|
||||
};
|
||||
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
|
||||
}
|
||||
|
||||
PurchaseProduct purchaseProduct = new PurchaseProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
PurchaseOrderId = purchaseOrder.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
|
||||
await purchaseProductsRepository.AddAsync(purchaseProduct, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||
|
||||
public class DeletePurchaseProductRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseOrderId { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
|
||||
{
|
||||
PurchaseProduct? purchaseProduct = await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||
using PyroFetes.DTO.PurchaseProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.PurchaseProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.PurchaseProducts;
|
||||
|
||||
public class PatchPurchaseProductQuantityEndpoint(
|
||||
PurchaseProductsRepository purchaseProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseProductQuantityDto, GetPurchaseProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
PurchaseProduct? purchaseProduct =
|
||||
await purchaseProductsRepository.FirstOrDefaultAsync(
|
||||
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
|
||||
|
||||
if (purchaseProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseProduct.Quantity = req.Quantity;
|
||||
await purchaseProductsRepository.UpdateAsync(purchaseProduct, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPurchaseProductDto>(purchaseProduct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Products;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||
|
||||
public class CreateQuotationProductEndpoint(
|
||||
QuotationProductsRepository quotationProductsRepository,
|
||||
ProductsRepository productsRepository,
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationProductDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/quotationProducts");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct)
|
||||
{
|
||||
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct);
|
||||
|
||||
if (quotation == null)
|
||||
{
|
||||
quotation = new Quotation()
|
||||
{
|
||||
Message = req.QuotationMessage ?? "",
|
||||
ConditionsSale = req.QuotationConditionsSale,
|
||||
};
|
||||
|
||||
await quotationsRepository.AddAsync(quotation, ct);
|
||||
}
|
||||
|
||||
QuotationProduct quotationProduct = new QuotationProduct()
|
||||
{
|
||||
ProductId = product.Id,
|
||||
QuotationId = quotation.Id,
|
||||
Quantity = req.Quantity
|
||||
};
|
||||
|
||||
await quotationProductsRepository.AddAsync(quotationProduct, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.QuotationProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||
|
||||
public class PatchQuotationProductQuantityEndpoint(
|
||||
QuotationProductsRepository quotationProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
QuotationProduct? quotationProduct =
|
||||
await quotationProductsRepository.FirstOrDefaultAsync(
|
||||
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
if (quotationProduct == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
quotationProduct.Quantity = req.Quantity;
|
||||
await quotationProductsRepository.UpdateAsync(quotationProduct, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), 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);
|
||||
}
|
||||
}
|
||||
+6
-9
@@ -1,10 +1,9 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.QuotationProducts;
|
||||
|
||||
namespace PyroFetes.Endpoints.QuotationProducts;
|
||||
namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
public class DeleteQuotationProductRequest
|
||||
{
|
||||
@@ -12,28 +11,26 @@ public class DeleteQuotationProductRequest
|
||||
public int QuotationId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
|
||||
public class DeleteProductFromQuotationEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId});
|
||||
AllowAnonymous();
|
||||
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.FirstOrDefaultAsync(
|
||||
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
|
||||
if (quotationProduct == null)
|
||||
if (quotationProduct is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
@@ -11,33 +10,26 @@ public class DeleteQuotationRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteQuotationEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationRequest>
|
||||
public class DeleteQuotationEndpoint(QuotationsRepository quotationsRepository) : Endpoint<DeleteQuotationRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/quotations/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Delete("/quotations/{@Id}", x => new { x.Id });
|
||||
Roles("Admin");
|
||||
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
if (quotation is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
|
||||
{
|
||||
await quotationProductsRepository.DeleteRangeAsync(quotation.QuotationProducts, ct);
|
||||
}
|
||||
|
||||
await quotationsRepository.DeleteAsync(quotation, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
@@ -12,11 +10,11 @@ public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository)
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/quotations");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(ct), ct);
|
||||
await Send.OkAsync(await quotationsRepository.ProjectToListAsync<GetQuotationDto>(new GetAllQuotationSpec(), ct), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
@@ -19,15 +17,15 @@ public class GetQuotationEndpoint(
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/quotations/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Get("/quotations/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
if (quotation is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.DTO.QuotationProduct.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
@@ -11,28 +9,27 @@ namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
public class PatchQuotationConditionsSaleEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto>
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/quotations/{@Id}/saleConditions", x => new { x.Id });
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct)
|
||||
{
|
||||
Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
Quotation? quotation = await quotationsRepository.SingleOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct);
|
||||
|
||||
if (quotation == null)
|
||||
if (quotation is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
quotation.ConditionsSale = req.ConditionsSale;
|
||||
await quotationsRepository.UpdateAsync(quotation, ct);
|
||||
mapper.Map(req, quotation);
|
||||
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||
await quotationsRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(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 PatchQuotationMessageEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationMessageDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/quotations/{@Id}/message", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationMessageDto 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
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 PatchQuotationProductQuantityEndpoint(
|
||||
QuotationProductsRepository quotationProductsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/quotations/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
|
||||
{
|
||||
QuotationProduct? quotationProduct =
|
||||
await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
|
||||
if (quotationProduct is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
mapper.Map(req, quotationProduct);
|
||||
|
||||
await quotationProductsRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Quotations;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
public class UpdateQuotationEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/quotations/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateQuotationDto 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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using FastEndpoints;
|
||||
using FastEndpoints.Security;
|
||||
using PyroFetes.DTO.Refresh.Request;
|
||||
using PyroFetes.DTO.Refresh.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Users;
|
||||
|
||||
namespace PyroFetes.Endpoints.Refresh;
|
||||
|
||||
public class RefreshTokenEndpoint(UsersRepository usersRepository) : Endpoint<RefreshTokenDto, GetRefreshTokenDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/refresh");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(RefreshTokenDto req, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
JwtSecurityTokenHandler handler = new();
|
||||
JwtSecurityToken? token = handler.ReadJwtToken(req.Token);
|
||||
string? username = token.Claims.FirstOrDefault(c => c.Type == "Name")?.Value;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(username))
|
||||
{
|
||||
await Send.UnauthorizedAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
User? login = await usersRepository.SingleOrDefaultAsync(new GetUserByNameSpec(username), ct);
|
||||
if (login == null)
|
||||
{
|
||||
await Send.UnauthorizedAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
string jwtToken = JwtBearer.CreateToken(o =>
|
||||
{
|
||||
o.SigningKey = "v9!Qx7#Lk2@pZ8$wR6!tN5%uF3&cD9^mH1*eY4";
|
||||
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||
if (login.Fonction is not null) o.User.Roles.Add(login.Fonction);
|
||||
o.User.Claims.Add(("Name", login.Name)!);
|
||||
o.User.Claims.Add(("Id", login.Id.ToString())!);
|
||||
});
|
||||
|
||||
GetRefreshTokenDto responseDto = new()
|
||||
{
|
||||
Token = jwtToken
|
||||
};
|
||||
|
||||
await Send.OkAsync(responseDto, ct);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await Send.UnauthorizedAsync(ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class CreateSettingEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateSettingDto, GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/settings");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
|
||||
{
|
||||
Setting setting = new Setting()
|
||||
{
|
||||
ElectronicSignature = req.ElectronicSignature,
|
||||
Logo = req.Logo
|
||||
};
|
||||
|
||||
await settingsRepository.AddAsync(setting, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class DeleteSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint<DeleteSettingRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/settings/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await settingsRepository.DeleteAsync(setting, ct);
|
||||
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,36 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
using PyroFetes.Services;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class GetSettingRequest
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSettingEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetSettingRequest, GetSettingDto>
|
||||
public class GetSettingEndpoint(SettingsRepository settingsRepository, StorageService storageService) : EndpointWithoutRequest<GetSettingDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/settings/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Get("/settings/");
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (setting == null)
|
||||
if (setting is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
GetSettingDto settingDto = new()
|
||||
{
|
||||
Id = setting.Id,
|
||||
ElectronicSignature = storageService.GetUrl(setting.ElectronicSignature!),
|
||||
Logo = storageService.GetUrl(setting.Logo!)
|
||||
};
|
||||
|
||||
await Send.OkAsync(settingDto, ct);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
using PyroFetes.Services;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class PatchSettingElectronicSignatureEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
|
||||
public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settingsRepository, StorageService storageService) : Endpoint<PatchSettingElectronicSignatureDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Patch("/settings/electronicSignature");
|
||||
AllowFormData();
|
||||
Roles("Admin");
|
||||
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (setting == null)
|
||||
if (setting is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.ElectronicSignature = req.ElectronicSignature;
|
||||
await settingsRepository.UpdateAsync(setting, ct);
|
||||
string key = await storageService.UploadFile(req.ElectronicSignature!, "electronicSignature", ct);
|
||||
setting.ElectronicSignature = key;
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
await settingsRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.SettingDTO.Request;
|
||||
using PyroFetes.DTO.SettingDTO.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Settings;
|
||||
using PyroFetes.Services;
|
||||
|
||||
namespace PyroFetes.Endpoints.Settings;
|
||||
|
||||
public class PatchSettingLogoEndpoint(
|
||||
SettingsRepository settingsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
|
||||
public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository, StorageService storageService) : Endpoint<PatchSettingLogoDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/settings/{@Id}/logo", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Patch("/settings/logo");
|
||||
AllowFormData();
|
||||
Roles("Admin");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
|
||||
{
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
|
||||
Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
|
||||
|
||||
if (setting == null)
|
||||
if (setting is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
setting.Logo = req.Logo;
|
||||
await settingsRepository.UpdateAsync(setting, ct);
|
||||
string key = await storageService.UploadFile(req.Logo!, "logo", ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
|
||||
setting.Logo = key;
|
||||
|
||||
await settingsRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
using PyroFetes.Specifications.Products;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class AddProductToSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
ProductsRepository productsRepository,
|
||||
PricesRepository pricesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreatePriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/suppliers/{@SupplierId}/{@ProductId}/", x => new { x.SupplierId, x.ProductId });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct);
|
||||
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
|
||||
if (supplier is null || product is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
Price? existingPrice = await pricesRepository.SingleOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct);
|
||||
if (existingPrice is not null)
|
||||
{
|
||||
await Send.StringAsync("Le fournisseur a déjà un prix pour ce produit.", 400, cancellation: ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await pricesRepository.AddAsync(mapper.Map<Price>(req), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,21 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class CreateSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||
public class CreateSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/suppliers");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = new Supplier()
|
||||
{
|
||||
Name = req.Name,
|
||||
Email = req.Email,
|
||||
Phone = req.Phone,
|
||||
Address = req.Address,
|
||||
City = req.City,
|
||||
ZipCode = req.ZipCode,
|
||||
DeliveryDelay = req.DeliveryDelay
|
||||
};
|
||||
|
||||
await suppliersRepository.AddAsync(supplier, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
await suppliersRepository.AddAsync(mapper.Map<Supplier>(req), ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class DeletePriceRequest
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int SupplierId { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteProductToSupplierEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/suppliers/{@SupplierId}/{@Product}", x => new { x.SupplierId, x.ProductId });
|
||||
Roles("Admin");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct)
|
||||
{
|
||||
Price? price = await pricesRepository.SingleOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct);
|
||||
|
||||
if (price is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await pricesRepository.DeleteAsync(price, ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
@@ -15,22 +14,21 @@ public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : E
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Delete("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Delete("/suppliers/{@Id}", x => new { x.Id });
|
||||
Roles("Admin");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
if (supplier is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
await suppliersRepository.DeleteAsync(supplier, ct);
|
||||
|
||||
await suppliersRepository.DeleteAsync(supplier, ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
@@ -10,7 +9,7 @@ public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) :
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/suppliers");
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CancellationToken ct)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
@@ -12,21 +11,19 @@ public class GetSupplierRequest
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
||||
public class GetSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
public class GetSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Get("/suppliers/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
if (supplier is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
|
||||
+8
-10
@@ -1,36 +1,34 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Price.Request;
|
||||
using PyroFetes.DTO.Price.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Prices;
|
||||
|
||||
namespace PyroFetes.Endpoints.Prices;
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class PatchPriceEndpoint(
|
||||
PricesRepository pricesRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto>
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId });
|
||||
AllowAnonymous();
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct)
|
||||
{
|
||||
Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct);
|
||||
Price? price = await pricesRepository.SingleOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct);
|
||||
|
||||
if (price == null)
|
||||
if (price is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
price.SellingPrice = req.SellingPrice;
|
||||
mapper.Map(req, price);
|
||||
|
||||
await pricesRepository.UpdateAsync(price, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetPriceDto>(price), ct);
|
||||
await pricesRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
@@ -8,28 +7,27 @@ using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class PatchSupplierDeliveryDelayEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
|
||||
public class PatchSupplierDeliveryDelayEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Patch("/suppliers/{@Id}/deliveryDelay", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
Supplier? supplier = await suppliersRepository.SingleOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
if (supplier is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||
await suppliersRepository.SaveChangesAsync(ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,31 @@
|
||||
using FastEndpoints;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PyroFetes.DTO.Supplier.Request;
|
||||
using PyroFetes.DTO.Supplier.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
using PyroFetes.Specifications.Suppliers;
|
||||
|
||||
namespace PyroFetes.Endpoints.Suppliers;
|
||||
|
||||
public class UpdateSupplierEndpoint(
|
||||
SuppliersRepository suppliersRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
||||
public class UpdateSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Put("/suppliers/{@Id}", x => new {x.Id});
|
||||
AllowAnonymous();
|
||||
Put("/suppliers/{@Id}", x => new { x.Id });
|
||||
Roles("Admin","Employe");
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
||||
{
|
||||
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
|
||||
|
||||
if (supplier == null)
|
||||
if (supplier is null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
supplier.Name = req.Name;
|
||||
supplier.Email = req.Email;
|
||||
supplier.Phone = req.Phone;
|
||||
supplier.Address = req.Address;
|
||||
supplier.City = req.City;
|
||||
supplier.ZipCode = req.ZipCode;
|
||||
supplier.DeliveryDelay = req.DeliveryDelay;
|
||||
mapper.Map(req, supplier);
|
||||
|
||||
await suppliersRepository.UpdateAsync(supplier, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
|
||||
await suppliersRepository.SaveChangesAsync(ct);
|
||||
await Send.NoContentAsync(ct);
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<Con
|
||||
|
||||
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct)
|
||||
{
|
||||
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
|
||||
|
||||
if (user == null)
|
||||
if (user is null)
|
||||
{
|
||||
await Send.UnauthorizedAsync(ct);
|
||||
return;
|
||||
@@ -29,15 +29,14 @@ public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<Con
|
||||
|
||||
if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password))
|
||||
{
|
||||
string jwtToken = JwtBearer.CreateToken(
|
||||
o =>
|
||||
{
|
||||
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||
if (user.Fonction != null) o.User.Roles.Add(user.Fonction);
|
||||
o.User.Claims.Add(("Name", user.Name)!);
|
||||
o.User.Claims.Add(("Id", user.Id.ToString())!);
|
||||
});
|
||||
string jwtToken = JwtBearer.CreateToken(o =>
|
||||
{
|
||||
o.SigningKey = "v9!Qx7#Lk2@pZ8$wR6!tN5%uF3&cD9^mH1*eY4";
|
||||
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||
if (user.Fonction is not null) o.User.Roles.Add(user.Fonction);
|
||||
o.User.Claims.Add(("Name", user.Name)!);
|
||||
o.User.Claims.Add(("Id", user.Id.ToString())!);
|
||||
});
|
||||
|
||||
GetTokenDto responseDto = new()
|
||||
{
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user