Refactor all code

This commit is contained in:
2026-05-24 17:22:03 +01:00
parent fe58e5e7e7
commit 656100d15e
117 changed files with 3317 additions and 1562 deletions
@@ -8,5 +8,5 @@ public class CreateDeliveryNoteDto
public int DelivererId { get; set; } public int DelivererId { get; set; }
public Dictionary<int,int>? ProductQuantities { get; set; } public Dictionary<int, int>? ProductQuantities { get; set; }
} }
+1 -20
View File
@@ -3,25 +3,6 @@
public class CreatePriceDto public class CreatePriceDto
{ {
public decimal SellingPrice { get; set; } public decimal SellingPrice { get; set; }
public int? SupplierId { get; set; } public int? SupplierId { get; set; }
public string? SupplierName { get; set; } public int ProductId { 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; }
} }
@@ -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,18 +2,8 @@
public class GetPriceDto public class GetPriceDto
{ {
public int Id { get; set; }
public decimal SellingPrice { 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 string? SupplierZipCode { get; set; }
public string? SupplierCity { get; set; }
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public string? ProductReference { get; set; } public string? ProductReference { get; set; }
public string? ProductName { get; set; } public string? ProductName { 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; }
}
@@ -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; }
}
@@ -14,15 +14,5 @@ public class GetProductDeliveryDto
public string? ProductLink { get; set; } public string? ProductLink { get; set; }
public int ProductMinimalQuantity { 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; } public int Quantity { get; set; }
} }
@@ -6,5 +6,6 @@ public class GetPurchaseOrderDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string? PurchaseConditions { get; set; } public string? PurchaseConditions { get; set; }
public int SupplierId { get; set; }
public List<GetPurchaseProductDto>? Products { get; set; } public List<GetPurchaseProductDto>? Products { get; set; }
} }
@@ -5,5 +5,4 @@ public class CreatePurchaseProductDto
public int Quantity { get; set; } public int Quantity { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public int PurchaseOrderId { 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 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 string? PurchaseOrderPurchaseConditions { get; set; }
}
@@ -3,7 +3,7 @@ namespace PyroFetes.DTO.PurchaseProduct.Response;
public class GetPurchaseProductDto public class GetPurchaseProductDto
{ {
public int ProductId { get; set; } public int ProductId { get; set; }
public string? ProductReferences { get; set; } public string? ProductReference { get; set; }
public string? ProductName { get; set; } public string? ProductName { get; set; }
public decimal ProductDuration {get; set;} public decimal ProductDuration {get; set;}
public int ProductCaliber { get; set; } public int ProductCaliber { get; set; }
@@ -15,8 +15,5 @@ public class GetPurchaseProductDto
public int ProductMinimalQuantity { get; set; } public int ProductMinimalQuantity { get; set; }
public decimal ProductPrice { get; set; } public decimal ProductPrice { get; set; }
public int PurchaseOrderId { get; set; }
public string? PurchaseOrderPurchaseConditions { get; set; }
public int Quantity { get; set; } public int Quantity { get; set; }
} }
@@ -1,6 +1,5 @@
namespace PyroFetes.DTO.QuotationProduct.Request; namespace PyroFetes.DTO.QuotationProduct.Request;
// Pour création global
public class CreateProductQuotationDto public class CreateProductQuotationDto
{ {
public int ProductId { get; set; } public int ProductId { get; set; }
@@ -1,22 +1,8 @@
namespace PyroFetes.DTO.QuotationProduct.Request; namespace PyroFetes.DTO.QuotationProduct.Request;
public class CreateQuotationProductDto public class AddQuotationProductDto
{ {
public int Quantity { get; set; } public int Quantity { get; set; }
public int QuotationId { get; set; } public int QuotationId { get; set; }
public string? QuotationMessage { get; set; }
public string? QuotationConditionsSale { get; set; }
public int ProductId { get; set; } public int ProductId { get; set; }
public int 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; }
} }
@@ -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 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; }
}
@@ -4,12 +4,8 @@ public class GetQuotationProductDto
{ {
public int Quantity { 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 ProductId { get; set; }
public string? ProductReferences { get; set; } public string? ProductReference { get; set; }
public string? ProductName { get; set; } public string? ProductName { get; set; }
public decimal ProductDuration {get; set;} public decimal ProductDuration {get; set;}
public int ProductCaliber { get; set; } public int ProductCaliber { get; set; }
@@ -2,6 +2,6 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class CreateSettingDto public class CreateSettingDto
{ {
public string? ElectronicSignature { get; set; } public IFormFile? ElectronicSignature { get; set; }
public string? Logo { get; set; } public IFormFile? Logo { get; set; }
} }
@@ -3,5 +3,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class PatchSettingElectronicSignatureDto public class PatchSettingElectronicSignatureDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string? ElectronicSignature { get; set; } public IFormFile? ElectronicSignature { get; set; }
} }
@@ -3,5 +3,5 @@ namespace PyroFetes.DTO.SettingDTO.Request;
public class PatchSettingLogoDto public class PatchSettingLogoDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string? Logo { get; set; } public IFormFile? Logo { get; set; }
} }
@@ -1,5 +1,4 @@
using PyroFetes.DTO.Price.Response; using PyroFetes.DTO.Price.Response;
using PyroFetes.DTO.Product.Response;
namespace PyroFetes.DTO.Supplier.Response; namespace PyroFetes.DTO.Supplier.Response;
@@ -13,6 +12,5 @@ public class GetSupplierDto
public string? ZipCode { get; set; } public string? ZipCode { get; set; }
public string? City { get; set; } public string? City { get; set; }
public int DeliveryDelay { get; set; } public int DeliveryDelay { get; set; }
public List<GetProductDto>? Products { get; set; }
public List<GetPriceDto>? Prices { get; set; } public List<GetPriceDto>? Prices { get; set; }
} }
@@ -6,9 +6,7 @@ using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Deliverers; namespace PyroFetes.Endpoints.Deliverers;
public class CreateDelivererEndpoint( public class CreateDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<CreateDelivererDto, GetDelivererDto>
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateDelivererDto, GetDelivererDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -18,13 +16,12 @@ public class CreateDelivererEndpoint(
public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct) public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct)
{ {
Deliverer newDeliverer = new Deliverer() Deliverer newDeliverer = new()
{ {
Transporter = req.Transporter, Transporter = req.Transporter,
}; };
await deliverersRepository.AddAsync(newDeliverer, ct); await deliverersRepository.AddAsync(newDeliverer, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(newDeliverer), ct);
} }
} }
@@ -9,28 +9,26 @@ public class DeleteDelivererRequest
{ {
public int DelivererId { get; set; } public int DelivererId { get; set; }
} }
public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest> public class DeleteDelivererEndpoint(DeliverersRepository deliverersRepository) : Endpoint<DeleteDelivererRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/deliverers/{@id}", x=>new {x.DelivererId}); Delete("/deliverers/{@Id}", x => new { x.DelivererId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteDelivererRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
await deliverersRepository.DeleteAsync(deliverer, ct); await deliverersRepository.DeleteAsync(deliverer, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(ct);
} }
} }
@@ -1,6 +1,4 @@
using AutoMapper.QueryableExtensions;
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response; using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -12,12 +10,10 @@ public class GetAllDelivererEndpoint(DeliverersRepository deliverersRepository)
{ {
Get("/deliverers"); Get("/deliverers");
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(CancellationToken ct) public override async Task HandleAsync(CancellationToken ct)
{ {
await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct); await Send.OkAsync(await deliverersRepository.ProjectToListAsync<GetDelivererDto>(ct), ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Response; using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -12,22 +11,19 @@ public class GetDelivererRequest
public int DelivererId { get; set; } public int DelivererId { get; set; }
} }
public class GetDelivererEndpoint( public class GetDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetDelivererRequest, GetDelivererDto>
{ {
public override void Configure() public override void Configure()
{ {
Get("/deliverers/{@id}", x=>new {x.DelivererId}); Get("/deliverers/{@Id}", x => new { x.DelivererId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetDelivererRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
@@ -35,5 +31,4 @@ public class GetDelivererEndpoint(
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct); await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Deliverer.Request; using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.Deliverer.Response; using PyroFetes.DTO.Deliverer.Response;
using PyroFetes.Models; using PyroFetes.Models;
@@ -8,32 +7,27 @@ using PyroFetes.Specifications.Deliverers;
namespace PyroFetes.Endpoints.Deliverers; namespace PyroFetes.Endpoints.Deliverers;
public class UpdateDelivererEndpoint( public class UpdateDelivererEndpoint(DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
DeliverersRepository deliverersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateDelivererDto, GetDelivererDto>
{ {
public override void Configure() public override void Configure()
{ {
Put("/deliverers/{@id}", x=>new {x.Id}); Put("/deliverers/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateDelivererDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
deliverer.Transporter = req.Transporter; mapper.Map(req, deliverer);
await deliverersRepository.UpdateAsync(deliverer,ct); await deliverersRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetDelivererDto>(deliverer), ct);
} }
} }
@@ -1,6 +1,5 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request; using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers; using PyroFetes.Specifications.Deliverers;
@@ -12,8 +11,7 @@ public class CreateDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository, DeliveryNotesRepository deliveryNotesRepository,
DeliverersRepository deliverersRepository, DeliverersRepository deliverersRepository,
ProductsRepository productsRepository, ProductsRepository productsRepository,
ProductDeliveriesRepository productDeliveriesRepository, ProductDeliveriesRepository productDeliveriesRepository) : Endpoint<CreateDeliveryNoteDto>
AutoMapper.IMapper mapper) : Endpoint<CreateDeliveryNoteDto, GetDeliveryNoteDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -23,46 +21,44 @@ public class CreateDeliveryNoteEndpoint(
public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct) public override async Task HandleAsync(CreateDeliveryNoteDto 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 is null)
if (deliverer == null)
{ {
await Send.StringAsync("No deliverer found", 404, cancellation: ct); await Send.NotFoundAsync(ct);
return; return;
} }
//Creating the Delivery Note //Creating the Delivery Note
DeliveryNote newDeliveryNote = new DeliveryNote() DeliveryNote newDeliveryNote = new()
{ {
TrackingNumber = req.TrackingNumber, TrackingNumber = req.TrackingNumber,
EstimateDeliveryDate = req.EstimateDeliveryDate, EstimateDeliveryDate = req.EstimateDeliveryDate,
ExpeditionDate = req.ExpeditionDate, ExpeditionDate = req.ExpeditionDate,
DelivererId = req.DelivererId, DelivererId = deliverer.Id,
Deliverer = deliverer, Deliverer = deliverer,
}; };
await deliveryNotesRepository.AddAsync(newDeliveryNote, ct); await deliveryNotesRepository.AddAsync(newDeliveryNote, ct);
foreach (var productQuantity in req.ProductQuantities!) if (req.ProductQuantities is not null)
{ {
Product? product = foreach (KeyValuePair<int, int> productQuantity in req.ProductQuantities)
await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
if (product != null)
{ {
ProductDelivery productDelivery = new ProductDelivery() Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct);
if (product is null) continue;
ProductDelivery productDelivery = new()
{ {
DeliveryNote = newDeliveryNote, DeliveryNote = newDeliveryNote,
Quantity = productQuantity.Value, Quantity = productQuantity.Value,
Product = product, Product = product,
ProductId = product.Id,
DeliveryNoteId = newDeliveryNote.Id DeliveryNoteId = newDeliveryNote.Id
}; };
await productDeliveriesRepository.AddAsync(productDelivery, ct); await productDeliveriesRepository.AddAsync(productDelivery, ct);
} }
} }
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(newDeliveryNote), ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,9 +1,7 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.Endpoints.Quotations;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes; using PyroFetes.Specifications.DeliveryNotes;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.DeliveryNotes; namespace PyroFetes.Endpoints.DeliveryNotes;
@@ -17,22 +15,21 @@ public class DeleteDeliveryNoteEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Delete("/deliveryNotes/{@Id}", x => new {x.Id}); Delete("/deliveryNotes/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteDeliveryNoteRequest req, CancellationToken ct)
{ {
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct); DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
if (deliveryNote == null) if (deliveryNote is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await deliveryNotesRepository.DeleteAsync(deliveryNote, ct); await deliveryNotesRepository.DeleteAsync(deliveryNote, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,6 +1,7 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Response; using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes; namespace PyroFetes.Endpoints.DeliveryNotes;
@@ -14,7 +15,6 @@ public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRep
public override async Task HandleAsync(CancellationToken ct) 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);
} }
} }
@@ -10,21 +10,22 @@ public class GetDeliveryNoteRequest
{ {
public int DeliveryNoteId { get; set; } public int DeliveryNoteId { get; set; }
} }
public class GetDeliveryNoteEndpoint( public class GetDeliveryNoteEndpoint(
DeliveryNotesRepository deliveryNotesRepository, DeliveryNotesRepository deliveryNotesRepository,
AutoMapper.IMapper mapper) : Endpoint<GetDeliveryNoteRequest, GetDeliveryNoteDto> AutoMapper.IMapper mapper) : Endpoint<GetDeliveryNoteRequest, GetDeliveryNoteDto>
{ {
public override void Configure() public override void Configure()
{ {
Get("/deliveryNotes/{@id}", x=> new {x.DeliveryNoteId}); Get("/deliveryNotes/{@Id}", x => new { x.DeliveryNoteId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
@@ -5,18 +5,14 @@ using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Services.Pdf; using PyroFetes.Services.Pdf;
using PyroFetes.Specifications.DeliveryNotes; using PyroFetes.Specifications.DeliveryNotes;
using PyroFetes.Specifications.Quotations;
namespace PyroFetes.Endpoints.DeliveryNotes; namespace PyroFetes.Endpoints.DeliveryNotes;
public class GetDeliveryNotePdfEndpoint( public class GetDeliveryNotePdfEndpoint(DeliveryNotesRepository deliveryNotesRepository, IDeliveryNotePdfService deliveryNotePdfService, SettingsRepository settingsRepository) : Endpoint<GetDeliveryNotePdfDto, byte[]>
DeliveryNotesRepository deliveryNotesRepository,
IDeliveryNotePdfService deliveryNotePdfService)
: Endpoint<GetDeliveryNotePdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/deliveryNotes/{@Id}/pdf", x => new {x.Id}); Get("/deliveryNotes/{@Id}/pdf", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf)); Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
@@ -24,20 +20,22 @@ public class GetDeliveryNotePdfEndpoint(
public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct) public override async Task HandleAsync(GetDeliveryNotePdfDto req, CancellationToken ct)
{ {
DeliveryNote? deliveryNote = await deliveryNotesRepository DeliveryNote? deliveryNote = await deliveryNotesRepository
.FirstOrDefaultAsync(new GetDeliveryNoteByIdWithProductsSpec(req.Id), ct); .SingleOrDefaultAsync(new GetDeliveryNoteByIdWithProductsSpec(req.Id), ct);
if (deliveryNote == null) Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
if (deliveryNote is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
var bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!); byte[] bytes = deliveryNotePdfService.Generate(deliveryNote, deliveryNote.ProductDeliveries!, setting!);
await Send.BytesAsync( await Send.BytesAsync(
bytes: bytes, bytes: bytes,
contentType: "application/pdf", contentType: "application/pdf",
fileName: $"bon-de-livraison-{deliveryNote.Id}.pdf", fileName: $"bon-de-livraison-{deliveryNote.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct); cancellation: ct);
} }
} }
@@ -1,45 +1,41 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request; using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
using PyroFetes.Specifications.DeliveryNotes; using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes; namespace PyroFetes.Endpoints.DeliveryNotes;
public class PatchRealDeliveryDateEndpoint( public class PatchRealDeliveryDateEndpoint(
DeliveryNotesRepository deliveryNotesRepository, DeliveryNotesRepository deliveryNotesRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto, GetDeliveryNoteDto> AutoMapper.IMapper mapper) : Endpoint<PatchDeliveryNoteRealDeliveryDateDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/deliveryNotes/{@id}", x=> new {x.Id}); Patch("/deliveryNotes/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct) public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct)
{ {
DeliveryNote? deliveryNoteToPath = DeliveryNote? deliveryNoteToPath = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id),ct);
if (deliveryNoteToPath == null) if (deliveryNoteToPath is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
if (deliveryNoteToPath.RealDeliveryDate != null) if (deliveryNoteToPath.RealDeliveryDate is not null)
{ {
await Send.StringAsync("Impossible de modifier la date.", 400); await Send.StringAsync("Impossible de modifier la date.", 400, cancellation: ct);
return; return;
} }
deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate; mapper.Map(req, deliveryNoteToPath);
await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct); await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct);
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNoteToPath), ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,40 +1,32 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.DeliveryNote.Request; using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.DTO.DeliveryNote.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.DeliveryNotes; using PyroFetes.Specifications.DeliveryNotes;
namespace PyroFetes.Endpoints.DeliveryNotes; namespace PyroFetes.Endpoints.DeliveryNotes;
public class UpdateDeliveryNoteEndpoint( public class UpdateDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateDeliveryNoteDto>
DeliveryNotesRepository deliveryNotesRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateDeliveryNoteDto, GetDeliveryNoteDto>
{ {
public override void Configure() public override void Configure()
{ {
Put("/deliveryNotes/{@Id}", x => new {x.Id}); Put("/deliveryNotes/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateDeliveryNoteDto req, CancellationToken ct) public override async Task HandleAsync(UpdateDeliveryNoteDto req, CancellationToken ct)
{ {
DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct); DeliveryNote? deliveryNote = await deliveryNotesRepository.SingleOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id), ct);
if (deliveryNote == null) if (deliveryNote is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
deliveryNote.TrackingNumber = req.TrackingNumber; mapper.Map(req, deliveryNote);
deliveryNote.EstimateDeliveryDate = req.EstimateDeliveryDate;
deliveryNote.ExpeditionDate = req.ExpeditionDate;
deliveryNote.RealDeliveryDate = req.RealDeliveryDate;
deliveryNote.DelivererId = req.DelivererId;
await deliveryNotesRepository.UpdateAsync(deliveryNote, ct); await deliveryNotesRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetDeliveryNoteDto>(deliveryNote), 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,8 +1,6 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.Endpoints.Deliverers;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Deliverers;
using PyroFetes.Specifications.Products; using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products; namespace PyroFetes.Endpoints.Products;
@@ -11,28 +9,26 @@ public class DeleteProductsRequest
{ {
public int ProductId { get; set; } public int ProductId { get; set; }
} }
public class DeleteProductEndpoint(ProductsRepository productsRepository) : Endpoint<DeleteProductsRequest> public class DeleteProductEndpoint(ProductsRepository productsRepository) : Endpoint<DeleteProductsRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/products/{@id}", x=>new {x.ProductId}); Delete("/products/{@Id}", x => new { x.ProductId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteProductsRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteProductsRequest req, CancellationToken ct)
{ {
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct);
if (product == null) if (product is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await productsRepository.DeleteAsync(product, ct); await productsRepository.DeleteAsync(product, ct);
await Send.OkAsync(ct); await Send.OkAsync(ct);
} }
} }
@@ -1,7 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Response; using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Products; namespace PyroFetes.Endpoints.Products;
@@ -1,4 +1,3 @@
using AutoMapper;
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Product.Response; using PyroFetes.DTO.Product.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Response; using PyroFetes.DTO.Product.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -18,7 +17,7 @@ public class GetProductEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/products/{@Id}", x => new {x.Id}); Get("/products/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
@@ -26,7 +25,7 @@ public class GetProductEndpoint(
{ {
Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct);
if (product == null) if (product is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
@@ -1,16 +1,12 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Products; using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products; namespace PyroFetes.Endpoints.Products;
public class PatchProductMinimalStockEndpoint( public class PatchProductMinimalStockEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto>
ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchProductMinimalStockDto, GetProductDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -20,17 +16,17 @@ public class PatchProductMinimalStockEndpoint(
public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
product.MinimalQuantity = req.MinimalQuantity; mapper.Map(req, product);
await productsRepository.UpdateAsync(product, ct);
await Send.OkAsync(mapper.Map<GetProductDto>(product), ct); await productsRepository.UpdateAsync(product, ct);
await Send.NoContentAsync(ct);
} }
} }
@@ -1,46 +1,32 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Products; using PyroFetes.Specifications.Products;
namespace PyroFetes.Endpoints.Products; namespace PyroFetes.Endpoints.Products;
public class UpdateProductEndpoint( public class UpdateProductEndpoint(ProductsRepository productsRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto>
ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateProductDto, GetProductDto>
{ {
public override void Configure() public override void Configure()
{ {
Put("/products/{@Id}", x => new {x.Id}); Put("/products/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
product.Reference = req.References; mapper.Map(req, product);
product.Name = req.Name;
product.Duration = req.Duration;
product.Caliber = req.Caliber;
product.ApprovalNumber = req.ApprovalNumber;
product.Weight = req.Weight;
product.Nec = req.Nec;
product.Image = req.Image;
product.Link = req.Link;
product.MinimalQuantity = req.MinimalQuantity;
await productsRepository.UpdateAsync(product, ct); await productsRepository.UpdateAsync(product, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetProductDto>(product), 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 });
AllowAnonymous();
}
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);
}
}
@@ -1,19 +1,18 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Request; using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Products; using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.PurchaseOrders; using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders;
public class CreatePurchaseOrder( public class CreatePurchaseOrder(
PurchaseOrdersRepository purchaseOrdersRepository, PurchaseOrdersRepository purchaseOrdersRepository,
ProductsRepository productsRepository, ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseOrderDto, GetPurchaseOrderDto> PurchaseProductsRepository purchaseProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreatePurchaseOrderDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -23,30 +22,35 @@ public class CreatePurchaseOrder(
public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct) public override async Task HandleAsync(CreatePurchaseOrderDto req, CancellationToken ct)
{ {
PurchaseOrder purchaseOrder = new PurchaseOrder PurchaseOrder purchaseOrder = mapper.Map<PurchaseOrder>(req);
{
PurchaseConditions = req.PurchaseConditions ?? "Conditions non précisées",
PurchaseProducts = new List<PurchaseProduct>()
};
foreach (var line in req.Products) if (req.Products != null)
{ {
var product = await productsRepository.GetByIdAsync(line.ProductId, ct); foreach (CreatePurchaseOrderProductDto line in req.Products)
if (product == null) {
Product? product = await productsRepository.SingleOrDefaultAsync(new GetProductByIdSpec(line.ProductId), ct);
if (product is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
purchaseOrder.PurchaseProducts.Add(new PurchaseProduct PurchaseProduct? purchaseProduct =
await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(line.ProductId, purchaseOrder.Id), ct);
if (purchaseProduct is not null)
{ {
ProductId = product.Id, await Send.StringAsync("Le produit est déjà dans le bon de commande", 400, cancellation: ct);
Quantity = line.Quantity, }
});
PurchaseProduct? productOnPurchase = mapper.Map<PurchaseProduct>(line);
productOnPurchase.PurchaseOrderId = purchaseOrder.Id;
await purchaseProductsRepository.AddAsync(productOnPurchase, ct);
}
} }
await purchaseOrdersRepository.AddAsync(purchaseOrder, ct); await purchaseOrdersRepository.AddAsync(purchaseOrder, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetPurchaseOrderDto>(purchaseOrder), ct);
} }
} }
@@ -1,10 +1,9 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseProducts; using PyroFetes.Specifications.PurchaseProducts;
namespace PyroFetes.Endpoints.PurchaseProducts; namespace PyroFetes.Endpoints.PurchaseOrders;
public class DeletePurchaseProductRequest public class DeletePurchaseProductRequest
{ {
@@ -12,27 +11,26 @@ public class DeletePurchaseProductRequest
public int PurchaseOrderId { get; set; } public int PurchaseOrderId { get; set; }
} }
public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest> public class DeleteProductFromPurchaseOrderEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseProductRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/purchaseProducts/{@ProductId}/{@PurchaseOrderId}", x => new {x.ProductId, x.PurchaseOrderId}); Delete("/purchaseOrders/{@ProductId}/{@PurchaseOrderId}", x => new { x.ProductId, x.PurchaseOrderId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct) public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct)
{ {
PurchaseProduct? purchaseProduct = await purchaseProductsRepository.FirstOrDefaultAsync( PurchaseProduct? purchaseProduct =
new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct); await purchaseProductsRepository.SingleOrDefaultAsync(new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct);
if (purchaseProduct == null) if (purchaseProduct is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct); await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders; using PyroFetes.Specifications.PurchaseOrders;
@@ -11,13 +10,11 @@ public class DeletePurchaseOrderRequest
public int Id { get; set; } public int Id { get; set; }
} }
public class DeletePurchaseOrderEndpoint( public class DeletePurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : Endpoint<DeletePurchaseOrderRequest>
PurchaseOrdersRepository purchaseOrdersRepository,
PurchaseProductsRepository purchaseProductsRepository) : Endpoint<DeletePurchaseOrderRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/purchaseOrders/{@Id}", x => new {x.Id}); Delete("/purchaseOrders/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
@@ -25,19 +22,13 @@ public class DeletePurchaseOrderEndpoint(
{ {
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct);
if (purchaseOrder == null) if (purchaseOrder is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any())
{
await purchaseProductsRepository.DeleteRangeAsync(purchaseOrder.PurchaseProducts, ct);
}
await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct); await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,7 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders;
@@ -1,7 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders; using PyroFetes.Specifications.PurchaseOrders;
@@ -13,21 +11,19 @@ public class GetPurchaseOrderRequest
public int Id { get; set; } public int Id { get; set; }
} }
public class GetPurchaseOrderEndpoint( public class GetPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
PurchaseOrdersRepository purchaseOrdersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetPurchaseOrderRequest, GetPurchaseOrderDto>
{ {
public override void Configure() public override void Configure()
{ {
Get("/purchaseOrders/{@Id}", x => new {x.Id}); Get("/purchaseOrders/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
@@ -5,37 +5,40 @@ using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Services.Pdf; using PyroFetes.Services.Pdf;
using PyroFetes.Specifications.PurchaseOrders; using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders;
public class GetPurchaseOrderPdfEndpoint( public class GetPurchaseOrderPdfEndpoint(
PurchaseOrdersRepository purchaseOrdersRepository, PurchaseOrdersRepository purchaseOrdersRepository,
IPurchaseOrderPdfService purchaseOrderPdfService) IPurchaseOrderPdfService purchaseOrderPdfService,
SettingsRepository settingsRepository)
: Endpoint<GetPurchaseOrderPdfDto, byte[]> : Endpoint<GetPurchaseOrderPdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/purchaseOrders/{@Id}/pdf", x => new {x.Id}); Get("/purchaseOrders/{@Id}/pdf", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf)); Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct) public override async Task HandleAsync(GetPurchaseOrderPdfDto req, CancellationToken ct)
{ {
PurchaseOrder? purchaseOrder = await purchaseOrdersRepository PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.SingleOrDefaultAsync(new GetPurchaseOrderByIdWithProductsSpec(req.Id), ct);
.FirstOrDefaultAsync(new GetPurchaseOrderByIdWithProductsSpec(req.Id), ct);
if (purchaseOrder == null) if (purchaseOrder is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
var bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!); Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
byte[] bytes = purchaseOrderPdfService.Generate(purchaseOrder, purchaseOrder.PurchaseProducts!, setting!);
await Send.BytesAsync( await Send.BytesAsync(
bytes: bytes, bytes: bytes,
contentType: "application/pdf", contentType: "application/pdf",
fileName: $"bon-de-commande-{purchaseOrder.Id}.pdf", fileName: $"bon-de-commande-{purchaseOrder.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct); cancellation: ct);
} }
} }
@@ -1,17 +1,14 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseOrder.Response;
using PyroFetes.DTO.PurchaseProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.PurchaseOrders; using PyroFetes.Specifications.PurchaseOrders;
namespace PyroFetes.Endpoints.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders;
public class PatchPurchaseOrderPurchaseConditionsEndpoint( public class PatchPurchaseOrderPurchaseConditionsEndpoint(PurchaseOrdersRepository purchaseOrdersRepository, AutoMapper.IMapper mapper)
PurchaseOrdersRepository purchaseOrdersRepository, : Endpoint<PatchPurchaseOrderPurchaseConditionsDto>
AutoMapper.IMapper mapper) : Endpoint<PatchPurchaseOrderPurchaseConditionsDto, GetPurchaseOrderDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -21,16 +18,16 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(
public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct) public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto 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); await Send.NotFoundAsync(ct);
return; return;
} }
purchaseOrder.PurchaseConditions = req.PurchaseConditions; mapper.Map(req, purchaseOrder);
await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct);
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 });
AllowAnonymous();
}
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.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);
}
}
@@ -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 AddProductoToQuotationEndpoint(
QuotationProductsRepository quotationProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<AddQuotationProductDto>
{
public override void Configure()
{
Post("/quotations/{@Id}/products", x => new { x.ProductId, x.QuotationId });
AllowAnonymous();
}
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);
}
}
@@ -1,15 +1,19 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Request;
using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Products;
using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.Quotations; namespace PyroFetes.Endpoints.Quotations;
public class CreateQuotationEndpoint( public class CreateQuotationEndpoint(
QuotationsRepository quotationsRepository, QuotationsRepository quotationsRepository,
QuotationProductsRepository quotationProductsRepository,
ProductsRepository productsRepository, ProductsRepository productsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateQuotationDto, GetQuotationDto> AutoMapper.IMapper mapper) : Endpoint<CreateQuotationDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -19,32 +23,36 @@ public class CreateQuotationEndpoint(
public override async Task HandleAsync(CreateQuotationDto req, CancellationToken ct) public override async Task HandleAsync(CreateQuotationDto req, CancellationToken ct)
{ {
Quotation quotation = new Quotation Quotation quotation = mapper.Map<Quotation>(req);
{ quotation.CustomerId = 1; // TODO: A changer
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) if (req.Products != null)
{ {
var product = await productsRepository.GetByIdAsync(line.ProductId, ct); foreach (CreateProductQuotationDto line in req.Products)
if (product == null) {
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); await Send.NotFoundAsync(ct);
return; return;
} }
quotation.QuotationProducts.Add(new QuotationProduct if (quotationProduct is not null)
{ {
ProductId = product.Id, await Send.StringAsync("Le produit est déjà dans le devis", 400, cancellation: ct);
Quantity = line.Quantity, }
});
QuotationProduct? productOnQuotation = mapper.Map<QuotationProduct>(line);
productOnQuotation.QuotationId = quotation.Id;
await quotationProductsRepository.AddAsync(productOnQuotation, ct);
}
} }
await quotationsRepository.AddAsync(quotation, ct); await quotationsRepository.AddAsync(quotation, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct);
} }
} }
@@ -1,10 +1,9 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts; using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.QuotationProducts; namespace PyroFetes.Endpoints.Quotations;
public class DeleteQuotationProductRequest public class DeleteQuotationProductRequest
{ {
@@ -12,28 +11,26 @@ public class DeleteQuotationProductRequest
public int QuotationId { get; set; } public int QuotationId { get; set; }
} }
public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest> public class DeleteProductFromQuotationEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationProductRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/quotationProducts/{@ProductId}/{@QuotationId}", x => new {x.ProductId, x.QuotationId}); Delete("/quotations/{@ProductId}/{@QuotationId}", x => new { x.ProductId, x.QuotationId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct)
{ {
QuotationProduct? quotationProduct = QuotationProduct? quotationProduct =
await quotationProductsRepository.FirstOrDefaultAsync( await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
if (quotationProduct == null) if (quotationProduct is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await quotationProductsRepository.DeleteAsync(quotationProduct, ct); await quotationProductsRepository.DeleteAsync(quotationProduct, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations; using PyroFetes.Specifications.Quotations;
@@ -11,33 +10,25 @@ public class DeleteQuotationRequest
public int Id { get; set; } public int Id { get; set; }
} }
public class DeleteQuotationEndpoint( public class DeleteQuotationEndpoint(QuotationsRepository quotationsRepository) : Endpoint<DeleteQuotationRequest>
QuotationsRepository quotationsRepository,
QuotationProductsRepository quotationProductsRepository) : Endpoint<DeleteQuotationRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/quotations/{@Id}", x => new {x.Id}); Delete("/quotations/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteQuotationRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
if (quotation.QuotationProducts != null && quotation.QuotationProducts.Any())
{
await quotationProductsRepository.DeleteRangeAsync(quotation.QuotationProducts, ct);
}
await quotationsRepository.DeleteAsync(quotation, ct); await quotationsRepository.DeleteAsync(quotation, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,8 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Quotations; namespace PyroFetes.Endpoints.Quotations;
@@ -1,7 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.Quotation.Response;
using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Quotations; using PyroFetes.Specifications.Quotations;
@@ -19,15 +17,15 @@ public class GetQuotationEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/quotations/{@Id}", x => new {x.Id}); Get("/quotations/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
@@ -10,33 +10,35 @@ namespace PyroFetes.Endpoints.Quotations;
public class GetQuotationPdfEndpoint( public class GetQuotationPdfEndpoint(
QuotationsRepository quotationRepository, QuotationsRepository quotationRepository,
IQuotationPdfService quotationPdfService) IQuotationPdfService quotationPdfService,
SettingsRepository settingsRepository)
: Endpoint<GetQuotationPdfDto, byte[]> : Endpoint<GetQuotationPdfDto, byte[]>
{ {
public override void Configure() public override void Configure()
{ {
Get("/quotations/{@Id}/pdf", x => new {x.Id}); Get("/quotations/{@Id}/pdf", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf)); Description(b => b.Produces<byte[]>(200, MediaTypeNames.Application.Pdf));
} }
public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct) public override async Task HandleAsync(GetQuotationPdfDto req, CancellationToken ct)
{ {
Quotation? quotation = await quotationRepository Quotation? quotation = await quotationRepository.SingleOrDefaultAsync(new GetQuotationByIdWithProductsSpec(req.Id), ct);
.FirstOrDefaultAsync(new GetQuotationByIdWithProductsSpec(req.Id), ct);
if (quotation == null) if (quotation is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
var bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!); Setting? setting = await settingsRepository.FirstOrDefaultAsync(ct);
byte[] bytes = quotationPdfService.Generate(quotation, quotation.QuotationProducts!, setting!);
await Send.BytesAsync( await Send.BytesAsync(
bytes: bytes, bytes: bytes,
contentType: "application/pdf", contentType: "application/pdf",
fileName: $"devis-{quotation.Id}.pdf", fileName: $"devis-{quotation.Id}{DateOnly.FromDateTime(DateTime.Now)}.pdf",
cancellation: ct); cancellation: ct);
} }
} }
@@ -9,7 +9,7 @@ namespace PyroFetes.Endpoints.Quotations;
public class PatchQuotationConditionsSaleEndpoint( public class PatchQuotationConditionsSaleEndpoint(
QuotationsRepository quotationsRepository, QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto, GetQuotationDto> AutoMapper.IMapper mapper) : Endpoint<PatchQuotationConditionsSaleDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -19,18 +19,17 @@ public class PatchQuotationConditionsSaleEndpoint(
public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
quotation.ConditionsSale = req.ConditionsSale; mapper.Map(req, quotation);
await quotationsRepository.UpdateAsync(quotation, ct);
await quotationsRepository.SaveChangesAsync(ct);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), 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 });
AllowAnonymous();
}
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);
}
}
@@ -1,37 +1,35 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Request;
using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.DTO.QuotationProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.QuotationProducts; using PyroFetes.Specifications.QuotationProducts;
namespace PyroFetes.Endpoints.QuotationProducts; namespace PyroFetes.Endpoints.Quotations;
public class PatchQuotationProductQuantityEndpoint( public class PatchQuotationProductQuantityEndpoint(
QuotationProductsRepository quotationProductsRepository, QuotationProductsRepository quotationProductsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto, GetQuotationProductDto> AutoMapper.IMapper mapper) : Endpoint<PatchQuotationProductQuantityDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/quotationProducts/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId }); Patch("/quotations/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct) public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct)
{ {
QuotationProduct? quotationProduct = QuotationProduct? quotationProduct =
await quotationProductsRepository.FirstOrDefaultAsync( await quotationProductsRepository.SingleOrDefaultAsync(new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct);
new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct); if (quotationProduct is null)
if (quotationProduct == null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
quotationProduct.Quantity = req.Quantity; mapper.Map(req, quotationProduct);
await quotationProductsRepository.UpdateAsync(quotationProduct, ct);
await Send.OkAsync(mapper.Map<GetQuotationProductDto>(quotationProduct), ct); await quotationProductsRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
} }
} }
@@ -9,7 +9,7 @@ namespace PyroFetes.Endpoints.Quotations;
public class UpdateQuotationEndpoint( public class UpdateQuotationEndpoint(
QuotationsRepository quotationsRepository, QuotationsRepository quotationsRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateQuotationDto, GetQuotationDto> AutoMapper.IMapper mapper) : Endpoint<UpdateQuotationDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -19,18 +19,17 @@ public class UpdateQuotationEndpoint(
public override async Task HandleAsync(UpdateQuotationDto req, CancellationToken ct) public override async Task HandleAsync(UpdateQuotationDto 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); await Send.NotFoundAsync(ct);
return; return;
} }
quotation.ConditionsSale = req.ConditionsSale; mapper.Map(req, quotation);
quotation.Message = req.Message;
await quotationsRepository.UpdateAsync(quotation, ct);
await Send.OkAsync(mapper.Map<GetQuotationDto>(quotation), ct); await quotationsRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
} }
} }
@@ -1,14 +1,11 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Settings; namespace PyroFetes.Endpoints.Settings;
public class CreateSettingEndpoint( public class CreateSettingEndpoint(SettingsRepository settingsRepository) : Endpoint<CreateSettingDto>
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateSettingDto, GetSettingDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -18,14 +15,21 @@ public class CreateSettingEndpoint(
public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct) public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct)
{ {
Setting setting = new Setting() // Encodage en base64
using MemoryStream memoryStream = new();
if (req.Logo != null) await req.Logo.CopyToAsync(memoryStream, ct);
byte[] logoBytes = memoryStream.ToArray();
if (req.ElectronicSignature != null) await req.ElectronicSignature.CopyToAsync(memoryStream, ct);
byte[] signatureBytes = memoryStream.ToArray();
Setting setting = new()
{ {
ElectronicSignature = req.ElectronicSignature, ElectronicSignature = Convert.ToBase64String(signatureBytes),
Logo = req.Logo Logo = Convert.ToBase64String(logoBytes)
}; };
await settingsRepository.AddAsync(setting, ct); await settingsRepository.AddAsync(setting, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings; using PyroFetes.Specifications.Settings;
@@ -15,22 +14,21 @@ public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endp
{ {
public override void Configure() public override void Configure()
{ {
Delete("/settings/{@Id}", x => new {x.Id}); Delete("/settings/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct)
{ {
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null) if (setting is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await settingsRepository.DeleteAsync(setting, ct); await settingsRepository.DeleteAsync(setting, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Response; using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -18,15 +17,15 @@ public class GetSettingEndpoint(
{ {
public override void Configure() public override void Configure()
{ {
Get("/settings/{@Id}", x => new {x.Id}); Get("/settings/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct) public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct)
{ {
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null) if (setting is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
@@ -1,36 +1,37 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings; using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings; namespace PyroFetes.Endpoints.Settings;
public class PatchSettingElectronicSignatureEndpoint( public class PatchSettingElectronicSignatureEndpoint(SettingsRepository settingsRepository) : Endpoint<PatchSettingElectronicSignatureDto>
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/settings/{@Id}/ElectronicSignature", x => new {x.Id}); Patch("/settings/{@Id}/ElectronicSignature", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct)
{ {
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null) if (setting is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
setting.ElectronicSignature = req.ElectronicSignature; // Encodage en base64
await settingsRepository.UpdateAsync(setting, ct); using MemoryStream memoryStream = new();
if (req.ElectronicSignature != null) await req.ElectronicSignature.CopyToAsync(memoryStream, ct);
byte[] signatureBytes = memoryStream.ToArray();
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct); setting.ElectronicSignature = Convert.ToBase64String(signatureBytes);
await settingsRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
} }
} }
@@ -1,36 +1,37 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Settings; using PyroFetes.Specifications.Settings;
namespace PyroFetes.Endpoints.Settings; namespace PyroFetes.Endpoints.Settings;
public class PatchSettingLogoEndpoint( public class PatchSettingLogoEndpoint(SettingsRepository settingsRepository) : Endpoint<PatchSettingLogoDto>
SettingsRepository settingsRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSettingLogoDto, GetSettingDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/settings/{@Id}/logo", x => new {x.Id}); Patch("/settings/{@Id}/logo", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct)
{ {
Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); Setting? setting = await settingsRepository.SingleOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct);
if (setting == null) if (setting is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
setting.Logo = req.Logo; // Encodage en base64
await settingsRepository.UpdateAsync(setting, ct); using MemoryStream memoryStream = new();
if (req.Logo != null) await req.Logo.CopyToAsync(memoryStream, ct);
byte[] logoBytes = memoryStream.ToArray();
await Send.OkAsync(mapper.Map<GetSettingDto>(setting), ct); setting.Logo = Convert.ToBase64String(logoBytes);
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 });
AllowAnonymous();
}
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,14 +1,11 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
namespace PyroFetes.Endpoints.Suppliers; namespace PyroFetes.Endpoints.Suppliers;
public class CreateSupplierEndpoint( public class CreateSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto>
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateSupplierDto, GetSupplierDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -18,19 +15,7 @@ public class CreateSupplierEndpoint(
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
{ {
Supplier? supplier = new Supplier() await suppliersRepository.AddAsync(mapper.Map<Supplier>(req), ct);
{ await Send.NoContentAsync(ct);
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);
} }
} }
@@ -1,10 +1,9 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Prices; using PyroFetes.Specifications.Prices;
namespace PyroFetes.Endpoints.Prices; namespace PyroFetes.Endpoints.Suppliers;
public class DeletePriceRequest public class DeletePriceRequest
{ {
@@ -12,26 +11,25 @@ public class DeletePriceRequest
public int SupplierId { get; set; } public int SupplierId { get; set; }
} }
public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest> public class DeleteProductToSupplierEndpoint(PricesRepository pricesRepository) : Endpoint<DeletePriceRequest>
{ {
public override void Configure() public override void Configure()
{ {
Delete("/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId}); Delete("/suppliers/{@SupplierId}/{@Product}", x => new { x.SupplierId, x.ProductId });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeletePriceRequest req, CancellationToken ct) public override async Task HandleAsync(DeletePriceRequest 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); await Send.NotFoundAsync(ct);
return; return;
} }
await pricesRepository.DeleteAsync(price, ct); await pricesRepository.DeleteAsync(price, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers; using PyroFetes.Specifications.Suppliers;
@@ -15,22 +14,21 @@ public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : E
{ {
public override void Configure() public override void Configure()
{ {
Delete("/suppliers/{@Id}", x => new {x.Id}); Delete("/suppliers/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
await suppliersRepository.DeleteAsync(supplier, ct); await suppliersRepository.DeleteAsync(supplier, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Response; using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Response; using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -12,21 +11,19 @@ public class GetSupplierRequest
public int Id { get; set; } public int Id { get; set; }
} }
public class GetSupplierEndpoint( public class GetSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetSupplierRequest, GetSupplierDto>
{ {
public override void Configure() public override void Configure()
{ {
Get("/suppliers/{@Id}", x => new {x.Id}); Get("/suppliers/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
@@ -1,15 +1,14 @@
using FastEndpoints; using FastEndpoints;
using PyroFetes.DTO.Price.Request; using PyroFetes.DTO.Price.Request;
using PyroFetes.DTO.Price.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Prices; using PyroFetes.Specifications.Prices;
namespace PyroFetes.Endpoints.Prices; namespace PyroFetes.Endpoints.Suppliers;
public class PatchPriceEndpoint( public class PatchPriceEndpoint(
PricesRepository pricesRepository, PricesRepository pricesRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto, GetPriceDto> AutoMapper.IMapper mapper) : Endpoint<PatchPriceSellingPriceDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -19,18 +18,17 @@ public class PatchPriceEndpoint(
public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
price.SellingPrice = req.SellingPrice; mapper.Map(req, price);
await pricesRepository.UpdateAsync(price, ct); await pricesRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetPriceDto>(price), ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response; using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models; using PyroFetes.Models;
@@ -8,28 +7,26 @@ using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers; namespace PyroFetes.Endpoints.Suppliers;
public class PatchSupplierDeliveryDelayEndpoint( public class PatchSupplierDeliveryDelayEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto>
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchSupplierDeliveryDelayDto, GetSupplierDto>
{ {
public override void Configure() public override void Configure()
{ {
Patch("/suppliers/{@Id}/deliveryDelay", x => new {x.Id}); Patch("/suppliers/{@Id}/deliveryDelay", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) 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); await Send.NotFoundAsync(ct);
return; return;
} }
supplier.DeliveryDelay = req.DeliveryDelay; supplier.DeliveryDelay = req.DeliveryDelay;
await suppliersRepository.UpdateAsync(supplier, ct); await suppliersRepository.SaveChangesAsync(ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct); await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
} }
@@ -1,43 +1,31 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Suppliers; using PyroFetes.Specifications.Suppliers;
namespace PyroFetes.Endpoints.Suppliers; namespace PyroFetes.Endpoints.Suppliers;
public class UpdateSupplierEndpoint( public class UpdateSupplierEndpoint(SuppliersRepository suppliersRepository, AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto>
SuppliersRepository suppliersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateSupplierDto, GetSupplierDto>
{ {
public override void Configure() public override void Configure()
{ {
Put("/suppliers/{@Id}", x => new {x.Id}); Put("/suppliers/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct) public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
{ {
Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct);
if (supplier is null)
if (supplier == null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
supplier.Name = req.Name; mapper.Map(req, supplier);
supplier.Email = req.Email;
supplier.Phone = req.Phone;
supplier.Address = req.Address;
supplier.City = req.City;
supplier.ZipCode = req.ZipCode;
supplier.DeliveryDelay = req.DeliveryDelay;
await suppliersRepository.UpdateAsync(supplier, ct); await suppliersRepository.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetSupplierDto>(supplier), ct);
} }
} }
@@ -19,9 +19,9 @@ public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<Con
public override async Task HandleAsync(ConnectUserDto req, CancellationToken ct) 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); await Send.UnauthorizedAsync(ct);
return; return;
@@ -29,12 +29,11 @@ public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint<Con
if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password)) if (BCrypt.Net.BCrypt.Verify(req.Password + user.Salt, user.Password))
{ {
string jwtToken = JwtBearer.CreateToken( string jwtToken = JwtBearer.CreateToken(o =>
o =>
{ {
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong"; o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
o.ExpireAt = DateTime.UtcNow.AddMinutes(15); o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
if (user.Fonction != null) o.User.Roles.Add(user.Fonction); if (user.Fonction is not null) o.User.Roles.Add(user.Fonction);
o.User.Claims.Add(("Name", user.Name)!); o.User.Claims.Add(("Name", user.Name)!);
o.User.Claims.Add(("Id", user.Id.ToString())!); o.User.Claims.Add(("Id", user.Id.ToString())!);
}); });
@@ -8,9 +8,7 @@ using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users; namespace PyroFetes.Endpoints.Users;
public class CreateUserEndpoint( public class CreateUserEndpoint(UsersRepository usersRepository) : Endpoint<CreateUserDto, GetUserDto>
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<CreateUserDto, GetUserDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -20,17 +18,17 @@ public class CreateUserEndpoint(
public override async Task HandleAsync(CreateUserDto req, CancellationToken ct) public override async Task HandleAsync(CreateUserDto req, CancellationToken ct)
{ {
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct); User? ckeckName = await usersRepository.SingleOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
if (ckeckName != null) if (ckeckName is not null)
{ {
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct); await Send.StringAsync("Ce nom d'utilisateur existe déjà.", 400, cancellation: ct);
return; return;
} }
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next(); string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
User user = new User() User user = new()
{ {
Name = req.Name, Name = req.Name,
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt), Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
@@ -40,7 +38,6 @@ public class CreateUserEndpoint(
}; };
await usersRepository.AddAsync(user, ct); await usersRepository.AddAsync(user, ct);
await Send.NoContentAsync(ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.Users; using PyroFetes.Specifications.Users;
@@ -15,22 +14,21 @@ public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint<Dele
{ {
public override void Configure() public override void Configure()
{ {
Delete("/users/{@Id}", x => new {x.Id}); Delete("/users/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct)
{ {
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null) if (user is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
await usersRepository.DeleteAsync(user, ct); await usersRepository.DeleteAsync(user, ct);
await Send.NoContentAsync(ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Response; using PyroFetes.DTO.User.Response;
using PyroFetes.Repositories; using PyroFetes.Repositories;
+4 -7
View File
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Response; using PyroFetes.DTO.User.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
@@ -12,21 +11,19 @@ public class GetUserRequest
public int Id { get; set; } public int Id { get; set; }
} }
public class GetUserEndpoint( public class GetUserEndpoint(UsersRepository usersRepository, AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<GetUserRequest, GetUserDto>
{ {
public override void Configure() public override void Configure()
{ {
Get("/users/{@Id}", x => new {x.Id}); Get("/users/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) public override async Task HandleAsync(GetUserRequest req, CancellationToken ct)
{ {
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null) if (user is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response; using PyroFetes.DTO.User.Response;
using PyroFetes.Models; using PyroFetes.Models;
@@ -8,9 +7,7 @@ using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users; namespace PyroFetes.Endpoints.Users;
public class PatchUserPasswordEndpoint( public class PatchUserPasswordEndpoint(UsersRepository usersRepository,AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<PatchUserPasswordDto, GetUserDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -20,9 +17,9 @@ public class PatchUserPasswordEndpoint(
public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct) public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct)
{ {
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
if (user == null) if (user is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
@@ -31,6 +28,6 @@ public class PatchUserPasswordEndpoint(
user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt); user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt);
await usersRepository.UpdateAsync(user, ct); await usersRepository.UpdateAsync(user, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,5 +1,4 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PasswordGenerator; using PasswordGenerator;
using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Request;
using PyroFetes.DTO.User.Response; using PyroFetes.DTO.User.Response;
@@ -9,30 +8,28 @@ using PyroFetes.Specifications.Users;
namespace PyroFetes.Endpoints.Users; namespace PyroFetes.Endpoints.Users;
public class UpdateUserEndpoint( public class UpdateUserEndpoint(UsersRepository usersRepository) : Endpoint<UpdateUserDto, GetUserDto>
UsersRepository usersRepository,
AutoMapper.IMapper mapper) : Endpoint<UpdateUserDto, GetUserDto>
{ {
public override void Configure() public override void Configure()
{ {
Put("/users/{@Id}", x => new {x.Id}); Put("/users/{@Id}", x => new { x.Id });
AllowAnonymous(); AllowAnonymous();
} }
public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct)
{ {
User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); User? user = await usersRepository.SingleOrDefaultAsync(new GetUserByIdSpec(req.Id), ct);
User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct); User? ckeckName = await usersRepository.SingleOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct);
if (user == null) if (user is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
if (ckeckName != null && ckeckName.Id != user.Id) if (ckeckName is not null && ckeckName.Id != user.Id)
{ {
await Send.StringAsync("Ce nom d'utilisateur existe déjà.",409, cancellation: ct); await Send.StringAsync("Ce nom d'utilisateur existe déjà.", 400, cancellation: ct);
return; return;
} }
@@ -46,6 +43,6 @@ public class UpdateUserEndpoint(
await usersRepository.UpdateAsync(user, ct); await usersRepository.UpdateAsync(user, ct);
await Send.OkAsync(mapper.Map<GetUserDto>(user), ct); await Send.NoContentAsync(ct);
} }
} }
@@ -1,7 +1,5 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.WareHouseProduct.Response; using PyroFetes.DTO.WareHouseProduct.Response;
using PyroFetes.Models;
using PyroFetes.Repositories; using PyroFetes.Repositories;
using PyroFetes.Specifications.WarehouseProducts; using PyroFetes.Specifications.WarehouseProducts;
@@ -23,7 +21,7 @@ public class GetTotalQuantityEndpoint(
public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct) public override async Task HandleAsync(GetTotalQuantityRequest req, CancellationToken ct)
{ {
bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct); bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, null), ct);
if (!exists) if (!exists)
{ {
@@ -31,8 +29,7 @@ public class GetTotalQuantityEndpoint(
return; return;
} }
int? totalQuantityNullable = await warehouseProductsRepository. int? totalQuantityNullable = await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
SumAsync(new GetProductTotalQuantitySpec(req.ProductId), wp => wp.Quantity, ct);
int totalQuantity = totalQuantityNullable ?? 0; int totalQuantity = totalQuantityNullable ?? 0;
@@ -1,13 +1,13 @@
using FastEndpoints; using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.WareHouseProduct.Request; using PyroFetes.DTO.WareHouseProduct.Request;
using PyroFetes.DTO.WareHouseProduct.Response; using PyroFetes.DTO.WareHouseProduct.Response;
using PyroFetes.Models; using PyroFetes.Models;
using PyroFetes.Repositories;
using PyroFetes.Specifications.WarehouseProducts;
namespace PyroFetes.Endpoints.WareHouseProducts; namespace PyroFetes.Endpoints.WareHouseProducts;
public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) public class PatchWareHouseProductQuantityEndpoint(WarehouseProductsRepository warehouseProductsRepository) : Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
: Endpoint<PatchWareHouseProductQuantityDto, GetWareHouseProductDto>
{ {
public override void Configure() public override void Configure()
{ {
@@ -17,25 +17,17 @@ public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database)
public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct) public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct)
{ {
WarehouseProduct? wareHouseProduct = WarehouseProduct? wareHouseProduct = await warehouseProductsRepository.FirstOrDefaultAsync(new GetWarehouseProductByProductIdSpec(req.ProductId, req.WareHouseId) , ct);
await database.WarehouseProducts.SingleOrDefaultAsync(
wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct);
if (wareHouseProduct == null) if (wareHouseProduct is null)
{ {
await Send.NotFoundAsync(ct); await Send.NotFoundAsync(ct);
return; return;
} }
wareHouseProduct.Quantity = req.Quantity; wareHouseProduct.Quantity = req.Quantity;
await database.SaveChangesAsync(ct); await warehouseProductsRepository.SaveChangesAsync(ct);
GetWareHouseProductDto responseDto = new() await Send.NoContentAsync(ct);
{
ProductId = wareHouseProduct.ProductId,
WareHouseId = wareHouseProduct.WarehouseId,
Quantity = wareHouseProduct.Quantity
};
await Send.OkAsync(responseDto, ct);
} }
} }
@@ -3,7 +3,6 @@ using PyroFetes.DTO.Deliverer.Request;
using PyroFetes.DTO.DeliveryNote.Request; using PyroFetes.DTO.DeliveryNote.Request;
using PyroFetes.DTO.Price.Request; using PyroFetes.DTO.Price.Request;
using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.ProductDelivery.Request;
using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Request;
using PyroFetes.DTO.PurchaseProduct.Request; using PyroFetes.DTO.PurchaseProduct.Request;
using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Request;
@@ -21,50 +20,65 @@ public class DtoToEntityMappings : Profile
public DtoToEntityMappings() public DtoToEntityMappings()
{ {
CreateMap<CreateDelivererDto, Deliverer>(); CreateMap<CreateDelivererDto, Deliverer>();
CreateMap<UpdateDelivererDto, Deliverer>(); CreateMap<UpdateDelivererDto, Deliverer>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateDeliveryNoteDto, DeliveryNote>(); CreateMap<CreateDeliveryNoteDto, DeliveryNote>();
CreateMap<UpdateDeliveryNoteDto, DeliveryNote>(); CreateMap<UpdateDeliveryNoteDto, DeliveryNote>()
CreateMap<PatchDeliveryNoteRealDeliveryDateDto, DeliveryNote>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchDeliveryNoteRealDeliveryDateDto, DeliveryNote>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreatePriceDto, Price>(); CreateMap<CreatePriceDto, Price>();
CreateMap<UpdatePriceDto, Price>(); CreateMap<PatchPriceSellingPriceDto, Price>()
CreateMap<PatchPriceSellingPriceDto, Price>(); .ForMember(dest => dest.ProductId, opt => opt.Ignore())
.ForMember(dest => dest.SupplierId, opt => opt.Ignore());
CreateMap<CreateProductDto, Product>(); CreateMap<UpdateProductDto, Product>()
CreateMap<UpdateProductDto, Product>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchProductMinimalStockDto, Product>(); CreateMap<PatchProductMinimalStockDto, Product>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateProductDeliveryDto, ProductDelivery>();
CreateMap<UpdateProductDeliveryDto, ProductDelivery>();
CreateMap<CreatePurchaseOrderDto, PurchaseOrder>(); CreateMap<CreatePurchaseOrderDto, PurchaseOrder>();
CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>(); CreateMap<PatchPurchaseOrderPurchaseConditionsDto,PurchaseOrder>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreatePurchaseProductDto, PurchaseProduct>(); CreateMap<CreatePurchaseProductDto, PurchaseProduct>();
CreateMap<UpdatePurchaseProductDto, PurchaseProduct>(); CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>()
CreateMap<PatchPurchaseProductQuantityDto, PurchaseProduct>(); .ForMember(dest => dest.ProductId, opt => opt.Ignore())
.ForMember(dest => dest.PurchaseOrderId, opt => opt.Ignore());
CreateMap<PatchQuotationConditionsSaleDto, Quotation>(); CreateMap<PatchQuotationConditionsSaleDto, Quotation>()
CreateMap<PatchQuotationMessageDto, Quotation>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchQuotationMessageDto, Quotation>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateProductQuotationDto, Quotation>(); CreateMap<CreateProductQuotationDto, Quotation>();
CreateMap<CreateQuotationProductDto, QuotationProduct>(); CreateMap<AddQuotationProductDto, QuotationProduct>();
CreateMap<UpdateQuotationProductDto, QuotationProduct>(); CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>()
CreateMap<PatchQuotationProductQuantityDto, QuotationProduct>(); .ForMember(dest => dest.ProductId, opt => opt.Ignore())
.ForMember(dest => dest.QuotationId, opt => opt.Ignore());
CreateMap<CreateSettingDto, Setting>(); CreateMap<CreateSettingDto, Setting>();
CreateMap<PatchSettingElectronicSignatureDto, Setting>(); CreateMap<PatchSettingElectronicSignatureDto, Setting>()
CreateMap<PatchSettingLogoDto, Setting>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchSettingLogoDto, Setting>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateSupplierDto, Supplier>(); CreateMap<CreateSupplierDto, Supplier>();
CreateMap<UpdateSupplierDto, Supplier>(); CreateMap<UpdateSupplierDto, Supplier>()
CreateMap<PatchSupplierDeliveryDelayDto, Supplier>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchSupplierDeliveryDelayDto, Supplier>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<CreateUserDto, User>(); CreateMap<CreateUserDto, User>();
CreateMap<UpdateUserDto, User>(); CreateMap<UpdateUserDto, User>()
CreateMap<PatchUserPasswordDto, User>(); .ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchUserPasswordDto, User>()
.ForMember(dest => dest.Id, opt => opt.Ignore());
CreateMap<PatchWareHouseProductQuantityDto, WarehouseProduct>(); CreateMap<PatchWareHouseProductQuantityDto, WarehouseProduct>()
.ForMember(dest => dest.ProductId, opt => opt.Ignore())
.ForMember(dest => dest.WarehouseId, opt => opt.Ignore());
} }
} }
@@ -24,46 +24,25 @@ public class EntityToDtoMappings : Profile
CreateMap<Supplier, GetSupplierDto>(); CreateMap<Supplier, GetSupplierDto>();
CreateMap<DeliveryNote, GetDeliveryNoteDto>(); CreateMap<DeliveryNote, GetDeliveryNoteDto>()
.ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.ProductDeliveries));
CreateMap<Price, GetPriceDto>(); CreateMap<Price, GetPriceDto>();
CreateMap<Product, GetProductDto>(); CreateMap<Product, GetProductDto>()
.ForMember(dest => dest.References, opt => opt.MapFrom(src => src.Reference));
CreateMap<ProductDelivery, GetProductDeliveryDto>(); CreateMap<ProductDelivery, GetProductDeliveryDto>();
// CreateMap<PurchaseOrder, GetPurchaseOrderDto>();
//
//CreateMap<PurchaseProduct, GetPurchaseProductDto>();
CreateMap<PurchaseOrder, GetPurchaseOrderDto>() CreateMap<PurchaseOrder, GetPurchaseOrderDto>()
.ForMember(dest => dest.Products, .ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.PurchaseProducts));
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))
.ForMember(dest => dest.ProductPrice, opt => opt.MapFrom(src => src.Product.Prices
.FirstOrDefault(p => p.SupplierId == src.PurchaseOrder!.SupplierId)
.SellingPrice));
// CreateMap<Quotation, GetQuotationDto>();
//
//CreateMap<QuotationProduct, GetQuotationProductDto>();
CreateMap<PurchaseProduct, GetPurchaseProductDto>();
CreateMap<Quotation, GetQuotationDto>() CreateMap<Quotation, GetQuotationDto>()
.ForMember(dest => dest.Products, .ForMember(dest => dest.Products, opt => opt.MapFrom(src => src.QuotationProducts));
opt => opt.MapFrom(src => src.QuotationProducts));
CreateMap<QuotationProduct, GetQuotationProductDto>() 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>(); CreateMap<Setting, GetSettingDto>();
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace PyroFetes.Migrations
{
/// <inheritdoc />
public partial class ChangeDatabaseName : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}
+1 -1
View File
@@ -80,7 +80,7 @@ app.UseAuthentication()
}) })
.UseSwaggerGen(); .UseSwaggerGen();
app.UseHttpsRedirection(); // app.UseHttpsRedirection();
app.UseCors(); app.UseCors();
+1 -9
View File
@@ -31,17 +31,9 @@
<_ContentIncludedByDefault Remove="wwwroot\Images\logo.jpg" /> <_ContentIncludedByDefault Remove="wwwroot\Images\logo.jpg" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="wwwroot\Images\logo.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="wwwroot\Images\signature.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Migrations\" /> <Folder Include="Migrations\" />
<Folder Include="wwwroot\" />
</ItemGroup> </ItemGroup>
</Project> </Project>
+4 -6
View File
@@ -63,15 +63,13 @@ public class PyroFetesDbContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
string connectionString = string connectionString =
"Server=localhost,1433;" + "Server=romaric-thibault.fr;" +
"Database=pyrofetes-db;" + "Database=PyroFetes-Sujet2;" +
"User Id=sa;" + "User Id=pyrofetes;" +
"Password=AdminMotDePasse!;" + "Password=Crablike8-Fringe-Swimmable;" +
"TrustServerCertificate=true;"; "TrustServerCertificate=true;";
optionsBuilder.UseSqlServer(connectionString); optionsBuilder.UseSqlServer(connectionString);
} }
// Models customization // Models customization
@@ -7,18 +7,18 @@ namespace PyroFetes.Services.Pdf;
public interface IDeliveryNotePdfService public interface IDeliveryNotePdfService
{ {
byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes); byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes, Setting setting);
} }
public class DeliveryNotePdfService : IDeliveryNotePdfService public class DeliveryNotePdfService : IDeliveryNotePdfService
{ {
public byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes) public byte[] Generate(DeliveryNote deliveryNote, List<ProductDelivery> lignes, Setting setting)
{ {
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg"); byte[] logo = Convert.FromBase64String(setting.Logo!);
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png"); byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
int total = 0; int total = 0;
int totalQuantity = 0; int totalQuantity = 0;
var document = Document.Create(container => Document document = Document.Create(container =>
{ {
container.Page(page => container.Page(page =>
{ {
@@ -48,7 +48,7 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
// Logo + société à droite // Logo + société à droite
row.ConstantItem(200).Column(col => row.ConstantItem(200).Column(col =>
{ {
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea); col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
col.Item().Height(20); col.Item().Height(20);
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold(); col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
col.Item().Height(5); col.Item().Height(5);
@@ -93,7 +93,7 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
header.Cell().Element(CellHeader).AlignRight().Text("Total"); header.Cell().Element(CellHeader).AlignRight().Text("Total");
}); });
foreach (var l in lignes) foreach (ProductDelivery l in lignes)
{ {
table.Cell().Element(CellBody).Text(l.Product?.Name); table.Cell().Element(CellBody).Text(l.Product?.Name);
table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString()); table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString());
@@ -123,7 +123,7 @@ public class DeliveryNotePdfService : IDeliveryNotePdfService
// Signature en bas à droite // Signature en bas à droite
page.Footer().AlignRight().Column(col => page.Footer().AlignRight().Column(col =>
{ {
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea); col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea);
}); });
}); });
}); });
@@ -7,18 +7,18 @@ namespace PyroFetes.Services.Pdf;
public interface IPurchaseOrderPdfService public interface IPurchaseOrderPdfService
{ {
byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes); byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes, Setting setting);
} }
public class PurchaseOrderPdfService : IPurchaseOrderPdfService public class PurchaseOrderPdfService : IPurchaseOrderPdfService
{ {
public byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes) public byte[] Generate(PurchaseOrder purchaseOrder, List<PurchaseProduct> lignes, Setting setting)
{ {
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg"); byte[] logo = Convert.FromBase64String(setting.Logo!);
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png"); byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
int totalQuantity = 0; int totalQuantity = 0;
decimal total = 0; decimal total = 0;
var document = Document.Create(container => Document document = Document.Create(container =>
{ {
container.Page(page => container.Page(page =>
{ {
@@ -42,7 +42,7 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
// Logo + société à droite // Logo + société à droite
row.ConstantItem(200).Column(col => row.ConstantItem(200).Column(col =>
{ {
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea); col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
col.Item().Height(20); col.Item().Height(20);
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold(); col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
col.Item().Height(5); col.Item().Height(5);
@@ -90,7 +90,7 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
header.Cell().Element(CellHeader).AlignRight().Text("Total"); header.Cell().Element(CellHeader).AlignRight().Text("Total");
}); });
foreach (var l in lignes) foreach (PurchaseProduct l in lignes)
{ {
decimal price = l.Product!.Prices! decimal price = l.Product!.Prices!
.FirstOrDefault(p => p.SupplierId == l.PurchaseOrder!.SupplierId) .FirstOrDefault(p => p.SupplierId == l.PurchaseOrder!.SupplierId)
@@ -140,7 +140,7 @@ public class PurchaseOrderPdfService : IPurchaseOrderPdfService
// Signature en bas à droite // Signature en bas à droite
page.Footer().AlignRight().Column(col => page.Footer().AlignRight().Column(col =>
{ {
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea); col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea);
}); });
}); });
}); });
@@ -1,5 +1,4 @@
using PyroFetes.Models; using PyroFetes.Models;
using QuestPDF.Companion;
using QuestPDF.Fluent; using QuestPDF.Fluent;
using QuestPDF.Helpers; using QuestPDF.Helpers;
using QuestPDF.Infrastructure; using QuestPDF.Infrastructure;
@@ -8,17 +7,17 @@ namespace PyroFetes.Services.Pdf;
public interface IQuotationPdfService public interface IQuotationPdfService
{ {
byte[] Generate(Quotation quotation, List<QuotationProduct> lignes); byte[] Generate(Quotation quotation, List<QuotationProduct> lignes, Setting setting);
} }
public class QuotationPdfService : IQuotationPdfService public class QuotationPdfService : IQuotationPdfService
{ {
public byte[] Generate(Quotation quotation, List<QuotationProduct> lignes) public byte[] Generate(Quotation quotation, List<QuotationProduct> lignes, Setting setting)
{ {
var logoPath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "logo.jpg"); byte[] logo = Convert.FromBase64String(setting.Logo!);
var signaturePath = Path.Combine(AppContext.BaseDirectory, "wwwroot", "Images", "signature.png"); byte[] signature = Convert.FromBase64String(setting.ElectronicSignature!);
int total = 0; int total = 0;
var document = Document.Create(container => Document document = Document.Create(container =>
{ {
container.Page(page => container.Page(page =>
{ {
@@ -42,7 +41,7 @@ public class QuotationPdfService : IQuotationPdfService
// Logo + société à droite // Logo + société à droite
row.ConstantItem(200).Column(col => row.ConstantItem(200).Column(col =>
{ {
col.Item().AlignRight().Height(70).Image(logoPath, ImageScaling.FitArea); col.Item().AlignRight().Height(70).Image(logo, ImageScaling.FitArea);
col.Item().Height(20); col.Item().Height(20);
col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold(); col.Item().AlignRight().Text("Pyro-Fêtes").SemiBold();
col.Item().Height(5); col.Item().Height(5);
@@ -90,7 +89,7 @@ public class QuotationPdfService : IQuotationPdfService
header.Cell().Element(CellHeader).AlignRight().Text("Total"); header.Cell().Element(CellHeader).AlignRight().Text("Total");
}); });
foreach (var l in lignes) foreach (QuotationProduct l in lignes)
{ {
table.Cell().Element(CellBody).Text(l.Product?.Name); table.Cell().Element(CellBody).Text(l.Product?.Name);
table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString()); table.Cell().Element(CellBody).AlignRight().Text(l.Quantity.ToString());
@@ -134,7 +133,7 @@ public class QuotationPdfService : IQuotationPdfService
// Signature en bas à droite // Signature en bas à droite
page.Footer().AlignRight().Column(col => page.Footer().AlignRight().Column(col =>
{ {
col.Item().AlignRight().Height(100).Image(signaturePath, ImageScaling.FitArea); col.Item().AlignRight().Height(100).Image(signature, ImageScaling.FitArea);
}); });
}); });
}); });
@@ -3,7 +3,7 @@ using PyroFetes.Models;
namespace PyroFetes.Specifications.Deliverers; namespace PyroFetes.Specifications.Deliverers;
public sealed class GetDelivererByIdSpec : Specification<Deliverer> public sealed class GetDelivererByIdSpec : SingleResultSpecification<Deliverer>
{ {
public GetDelivererByIdSpec(int delivererId) public GetDelivererByIdSpec(int delivererId)
{ {
@@ -0,0 +1,16 @@
using Ardalis.Specification;
using PyroFetes.Models;
namespace PyroFetes.Specifications.DeliveryNotes;
public class GetAllDeliveryNoteSpec : Specification<DeliveryNote>
{
public GetAllDeliveryNoteSpec()
{
Query
.Include(x => x.Deliverer)
.Include(x => x.ProductDeliveries)!
.ThenInclude(x => x.Product)
.Where(x => true);
}
}
@@ -3,11 +3,14 @@ using PyroFetes.Models;
namespace PyroFetes.Specifications.DeliveryNotes; namespace PyroFetes.Specifications.DeliveryNotes;
public sealed class GetDeliveryNoteByIdSpec : Specification<DeliveryNote> public sealed class GetDeliveryNoteByIdSpec : SingleResultSpecification<DeliveryNote>
{ {
public GetDeliveryNoteByIdSpec(int deliveryNoteId) public GetDeliveryNoteByIdSpec(int deliveryNoteId)
{ {
Query Query
.Include(x => x.Deliverer)
.Include(x => x.ProductDeliveries!)
.ThenInclude(x => x.Product)
.Where(x => x.Id == deliveryNoteId); .Where(x => x.Id == deliveryNoteId);
} }
} }
@@ -3,13 +3,13 @@ using PyroFetes.Models;
namespace PyroFetes.Specifications.DeliveryNotes; namespace PyroFetes.Specifications.DeliveryNotes;
public class GetDeliveryNoteByIdWithProductsSpec : Specification<DeliveryNote> public class GetDeliveryNoteByIdWithProductsSpec : SingleResultSpecification<DeliveryNote>
{ {
public GetDeliveryNoteByIdWithProductsSpec(int deliveryNoteId) public GetDeliveryNoteByIdWithProductsSpec(int deliveryNoteId)
{ {
Query Query
.Where(d => d.Id == deliveryNoteId) .Where(x => x.Id == deliveryNoteId)
.Include(d => d.ProductDeliveries!) .Include(x => x.ProductDeliveries!)
.ThenInclude(dp => dp.Product); .ThenInclude(p => p.Product);
} }
} }
@@ -3,11 +3,11 @@ using PyroFetes.Models;
namespace PyroFetes.Specifications.Prices; namespace PyroFetes.Specifications.Prices;
public sealed class GetPriceByProductIdAndSupplierIdSpec : Specification<Price> public sealed class GetPriceByProductIdAndSupplierIdSpec : SingleResultSpecification<Price>
{ {
public GetPriceByProductIdAndSupplierIdSpec(int? productId, int? supplierId) public GetPriceByProductIdAndSupplierIdSpec(int? productId, int? supplierId)
{ {
Query Query
.Where(p => p.ProductId == productId && p.SupplierId == supplierId); .Where(x => x.ProductId == productId && x.SupplierId == supplierId);
} }
} }

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