fix error and add CreatePurchaseOrder.cs
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
using PyroFetes.DTO.PurchaseProduct.Request;
|
||||||
|
|
||||||
|
namespace PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
|
||||||
|
public class CreatePurchaseOrderDto
|
||||||
|
{
|
||||||
|
public string? PurchaseConditions { get; set; }
|
||||||
|
public List<CreatePurchaseOrderProductDto>? Products { get; set; }
|
||||||
|
}
|
||||||
@@ -6,5 +6,5 @@ public class GetPurchaseOrderDto
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string? PurchaseConditions { get; set; }
|
public string? PurchaseConditions { get; set; }
|
||||||
public List<GetPurchaseProductDto>? GetPurchaseProductDto { 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; }
|
||||||
|
}
|
||||||
@@ -7,11 +7,11 @@ public class UpdatePurchaseProductDto
|
|||||||
|
|
||||||
public int Quantity { get; set; }
|
public int Quantity { get; set; }
|
||||||
|
|
||||||
public int ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public decimal ProductCaliber { get; set; }
|
public int ProductCaliber { get; set; }
|
||||||
public int ProductApprovalNumber { get; set; }
|
public string? ProductApprovalNumber { get; set; }
|
||||||
public decimal ProductWeight { get; set; }
|
public decimal ProductWeight { get; set; }
|
||||||
public decimal ProductNec { get; set; }
|
public decimal ProductNec { get; set; }
|
||||||
public string? ProductImage { get; set; }
|
public string? ProductImage { get; set; }
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ public class GetPurchaseProductDto
|
|||||||
public string? ProductReferences { get; set; }
|
public string? ProductReferences { get; set; }
|
||||||
public string? ProductName { get; set; }
|
public string? ProductName { get; set; }
|
||||||
public decimal ProductDuration {get; set;}
|
public decimal ProductDuration {get; set;}
|
||||||
public decimal ProductCaliber { get; set; }
|
public int ProductCaliber { get; set; }
|
||||||
public int ProductApprovalNumber { get; set; }
|
public string? ProductApprovalNumber { get; set; }
|
||||||
public decimal ProductWeight { get; set; }
|
public decimal ProductWeight { get; set; }
|
||||||
public decimal ProductNec { get; set; }
|
public decimal ProductNec { get; set; }
|
||||||
public string? ProductImage { get; set; }
|
public string? ProductImage { get; set; }
|
||||||
|
|||||||
52
PyroFetes/Endpoints/PurchaseOrders/CreatePurchaseOrder.cs
Normal file
52
PyroFetes/Endpoints/PurchaseOrders/CreatePurchaseOrder.cs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Request;
|
||||||
|
using PyroFetes.DTO.PurchaseOrder.Response;
|
||||||
|
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.PurchaseOrders;
|
||||||
|
|
||||||
|
public class CreatePurchaseOrder(
|
||||||
|
PurchaseOrdersRepository purchaseOrdersRepository,
|
||||||
|
ProductsRepository productsRepository,
|
||||||
|
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseOrderDto, GetPurchaseOrderDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/purchaseOrders");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
var purchaseOrder = new PurchaseOrder
|
||||||
|
{
|
||||||
|
PurchaseConditions = req.PurchaseConditions ?? "Conditions non précisées",
|
||||||
|
PurchaseProducts = new List<PurchaseProduct>()
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var line in req.Products)
|
||||||
|
{
|
||||||
|
var product = await productsRepository.GetByIdAsync(line.ProductId, ct);
|
||||||
|
if (product == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
purchaseOrder.PurchaseProducts.Add(new PurchaseProduct
|
||||||
|
{
|
||||||
|
ProductId = product.Id,
|
||||||
|
Quantity = line.Quantity,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,6 +38,7 @@ public class DtoToEntityMappings : Profile
|
|||||||
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
|
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
|
||||||
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
|
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
|
||||||
|
|
||||||
|
CreateMap<CreatePurchaseOrderDto, PurchaseOrder>();
|
||||||
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>();
|
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>();
|
||||||
|
|
||||||
CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
|
CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
|
||||||
|
|||||||
@@ -32,9 +32,19 @@ public class EntityToDtoMappings : Profile
|
|||||||
|
|
||||||
CreateMap<ProductDelivery, GetProductDeliveryDto>();
|
CreateMap<ProductDelivery, GetProductDeliveryDto>();
|
||||||
|
|
||||||
CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
|
// CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
|
||||||
|
//
|
||||||
|
// CreateMap<PurchaseProduct, GetPurchaseProductDto>();
|
||||||
|
|
||||||
CreateMap<PurchaseProduct, GetPurchaseProductDto>();
|
CreateMap<PurchaseOrder, GetPurchaseOrderDto>()
|
||||||
|
.ForMember(dest => dest.Products,
|
||||||
|
opt => opt.MapFrom(src => src.PurchaseProducts));
|
||||||
|
|
||||||
|
CreateMap<PurchaseProduct, GetPurchaseProductDto>()
|
||||||
|
.ForMember(dest => dest.ProductId, opt => opt.MapFrom(src => src.ProductId))
|
||||||
|
.ForMember(dest => dest.Quantity, opt => opt.MapFrom(src => src.Quantity))
|
||||||
|
.ForMember(dest => dest.ProductName, opt => opt.MapFrom(src => src.Product.Name))
|
||||||
|
.ForMember(dest => dest.ProductReferences, opt => opt.MapFrom(src => src.Product.Reference));
|
||||||
|
|
||||||
CreateMap<Quotation, GetQuotationDto>();
|
CreateMap<Quotation, GetQuotationDto>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user