added CreateQuotationEndpoint.cs
This commit is contained in:
10
PyroFetes/DTO/Quotation/Request/CreateQuotationDto.cs
Normal file
10
PyroFetes/DTO/Quotation/Request/CreateQuotationDto.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using PyroFetes.DTO.QuotationProduct.Request;
|
||||
|
||||
namespace PyroFetes.DTO.Quotation.Request;
|
||||
|
||||
public class CreateQuotationDto
|
||||
{
|
||||
public string? Message { get; set; }
|
||||
public string? ConditionsSale { get; set; }
|
||||
public List<CreateProductQuotationDto>? Products { 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;
|
||||
|
||||
// Pour création global
|
||||
public class CreateProductQuotationDto
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public class CreatePurchaseOrder(
|
||||
|
||||
public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct)
|
||||
{
|
||||
var purchaseOrder = new PurchaseOrder
|
||||
PurchaseOrder purchaseOrder = new PurchaseOrder
|
||||
{
|
||||
PurchaseConditions = req.PurchaseConditions ?? "Conditions non précisées",
|
||||
PurchaseProducts = new List<PurchaseProduct>()
|
||||
|
||||
50
PyroFetes/Endpoints/Quotations/CreateQuotationEndpoint.cs
Normal file
50
PyroFetes/Endpoints/Quotations/CreateQuotationEndpoint.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using FastEndpoints;
|
||||
using PyroFetes.DTO.Quotation.Request;
|
||||
using PyroFetes.DTO.Quotation.Response;
|
||||
using PyroFetes.Models;
|
||||
using PyroFetes.Repositories;
|
||||
|
||||
namespace PyroFetes.Endpoints.Quotations;
|
||||
|
||||
public class CreateQuotationEndpoint(
|
||||
QuotationsRepository quotationsRepository,
|
||||
ProductsRepository productsRepository,
|
||||
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationDto, GetQuotationDto>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Post("/quotations");
|
||||
AllowAnonymous();
|
||||
}
|
||||
|
||||
public override async Task HandleAsync(CreateQuotationDto req, CancellationToken ct)
|
||||
{
|
||||
Quotation quotation = new Quotation
|
||||
{
|
||||
Message = req.Message,
|
||||
ConditionsSale = req.ConditionsSale ?? "Conditions non précisées",
|
||||
CustomerId = 1, // A changer
|
||||
QuotationProducts = new List<QuotationProduct>()
|
||||
};
|
||||
|
||||
foreach (var line in req.Products)
|
||||
{
|
||||
var product = await productsRepository.GetByIdAsync(line.ProductId, ct);
|
||||
if (product == null)
|
||||
{
|
||||
await Send.NotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
quotation.QuotationProducts.Add(new QuotationProduct
|
||||
{
|
||||
ProductId = product.Id,
|
||||
Quantity = line.Quantity,
|
||||
});
|
||||
}
|
||||
|
||||
await quotationsRepository.AddAsync(quotation, ct);
|
||||
|
||||
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ public class DtoToEntityMappings : Profile
|
||||
|
||||
CreateMap<PatchQuotationConditionsSaleDto, Quotation>();
|
||||
CreateMap<PatchQuotationMessageDto, Quotation>();
|
||||
CreateMap<CreateProductQuotationDto, Quotation>();
|
||||
|
||||
CreateMap<CreateQuotationProductDto, QuotationProduct>();
|
||||
CreateMap<UpdateQuotationProductDto, QuotationProduct>();
|
||||
|
||||
@@ -46,9 +46,19 @@ public class EntityToDtoMappings : Profile
|
||||
.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>();
|
||||
//
|
||||
// CreateMap<QuotationProduct, GetQuotationProductDto>();
|
||||
|
||||
CreateMap<QuotationProduct, GetQuotationProductDto>();
|
||||
CreateMap<Quotation, GetQuotationDto>()
|
||||
.ForMember(dest => dest.Products,
|
||||
opt => opt.MapFrom(src => src.QuotationProducts));
|
||||
|
||||
CreateMap<QuotationProduct, GetQuotationProductDto>()
|
||||
.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<Setting, GetSettingDto>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user