From ae834d1e3c59bc0b2fd26a988d317833d1645c50 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 13 Nov 2025 16:31:00 +0100 Subject: [PATCH 01/16] Adapted Price Endpoints --- .../Deliverers/CreateDelivererEndpoint.cs | 2 +- .../Endpoints/Price/CreatePriceEndpoint.cs | 104 ------------------ .../Endpoints/Prices/CreatePriceEndpoint.cs | 83 ++++++++++++++ .../{Price => Prices}/DeletePriceEndpoint.cs | 0 .../{Price => Prices}/PatchPriceEndpoint.cs | 0 .../Repositories/DeliverersRepository.cs | 2 +- PyroFetes/Repositories/PricesRepository.cs | 5 + PyroFetes/Repositories/ProductsRepository.cs | 5 + PyroFetes/Repositories/SuppliersRepository.cs | 5 + .../GetPriceByProductIdAndSupplierIdSpec.cs | 13 +++ .../Products/GetProductByIdSpec.cs | 13 +++ .../Suppliers/GetSupplierByIdSpec.cs | 13 +++ 12 files changed, 139 insertions(+), 106 deletions(-) delete mode 100644 PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs create mode 100644 PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs rename PyroFetes/Endpoints/{Price => Prices}/DeletePriceEndpoint.cs (100%) rename PyroFetes/Endpoints/{Price => Prices}/PatchPriceEndpoint.cs (100%) create mode 100644 PyroFetes/Repositories/PricesRepository.cs create mode 100644 PyroFetes/Repositories/ProductsRepository.cs create mode 100644 PyroFetes/Repositories/SuppliersRepository.cs create mode 100644 PyroFetes/Specifications/Prices/GetPriceByProductIdAndSupplierIdSpec.cs create mode 100644 PyroFetes/Specifications/Products/GetProductByIdSpec.cs create mode 100644 PyroFetes/Specifications/Suppliers/GetSupplierByIdSpec.cs diff --git a/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs b/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs index d7f67ff..8661c64 100644 --- a/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs +++ b/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs @@ -7,7 +7,7 @@ using PyroFetes.Repositories; namespace PyroFetes.Endpoints.Deliverers; public class CreateDelivererEndpoint( - DeliverersRepository deliverersRepository, + DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint { public override void Configure() diff --git a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs deleted file mode 100644 index d65ba2d..0000000 --- a/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs +++ /dev/null @@ -1,104 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Price.Request; -using PyroFetes.DTO.Price.Response; - -namespace PyroFetes.Endpoints.Price; - -public class CreatePriceEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Post("/api/prices"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct) - { - // Gestion du fournisseur - var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct); - if (supplier == null) - { - supplier = new Models.Supplier() - { - Name = req.SupplierName, - Email = req.SupplierEmail, - Phone = req.SupplierPhone, - Address = req.SupplierAddress, - City = req.SupplierCity, - ZipCode = req.SupplierZipCode, - DeliveryDelay = req.SupplierDeliveryDelay - }; - database.Suppliers.Add(supplier); - await database.SaveChangesAsync(ct); - } - - // Gestion du produit - var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct); - if (product == null) - { - product = new Models.Product() - { - Reference = req.ProductReferences, - Name = req.ProductName, - Duration = req.ProductDuration, - Caliber = req.ProductCaliber, - ApprovalNumber = req.ProductApprovalNumber, - Weight = req.ProductWeight, - Nec = req.ProductNec, - Image = req.ProductImage, - Link = req.ProductLink, - MinimalQuantity = req.ProductMinimalQuantity - }; - database.Products.Add(product); - await database.SaveChangesAsync(ct); - } - - // Vérifie si le prix existe déjà pour ce fournisseur et produit - var existingPrice = await database.Prices - .SingleOrDefaultAsync(p => p.ProductId == product.Id && p.SupplierId == supplier.Id, ct); - - if (existingPrice != null) - { - await Send.ConflictAsync("Le fournisseur a déjà un prix pour ce produit.", ct); - return; - } - - // Création du prix - var priceAdded = new Models.Price() - { - SellingPrice = req.SellingPrice, - SupplierId = supplier.Id, - ProductId = product.Id - }; - database.Prices.Add(priceAdded); - await database.SaveChangesAsync(ct); - - // Création du DTO de réponse - var responseDto = new GetPriceDto() - { - SellingPrice = priceAdded.SellingPrice, - SupplierId = supplier.Id, - ProductId = product.Id, - SupplierName = supplier.Name, - SupplierEmail = supplier.Email, - SupplierPhone = supplier.Phone, - SupplierAddress = supplier.Address, - SupplierCity = supplier.City, - SupplierZipCode = supplier.ZipCode, - SupplierDeliveryDelay = supplier.DeliveryDelay, - ProductReferences = product.Reference, - ProductName = product.Name, - ProductDuration = product.Duration, - ProductCaliber = product.Caliber, - ProductApprovalNumber = product.ApprovalNumber, - ProductWeight = product.Weight, - ProductNec = product.Nec, - ProductImage = product.Image, - ProductLink = product.Link, - ProductMinimalQuantity = product.MinimalQuantity - }; - - await Send.OkAsync(responseDto, ct); - } -} diff --git a/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs new file mode 100644 index 0000000..fcdbde3 --- /dev/null +++ b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs @@ -0,0 +1,83 @@ +using FastEndpoints; +using PyroFetes.DTO.Price.Request; +using PyroFetes.DTO.Price.Response; +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 +{ + public override void Configure() + { + Post("/api/prices"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct) + { + // Gestion du fournisseur + var supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct); + if (supplier == null) + { + supplier = new Models.Supplier() + { + Name = req.SupplierName, + Email = req.SupplierEmail, + Phone = req.SupplierPhone, + Address = req.SupplierAddress, + City = req.SupplierCity, + ZipCode = req.SupplierZipCode, + DeliveryDelay = req.SupplierDeliveryDelay + }; + await suppliersRepository.AddAsync(supplier, ct); + } + + // Gestion du produit + var product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + if (product == null) + { + product = new Models.Product() + { + Reference = req.ProductReferences, + Name = req.ProductName, + Duration = req.ProductDuration, + Caliber = req.ProductCaliber, + ApprovalNumber = req.ProductApprovalNumber, + Weight = req.ProductWeight, + Nec = req.ProductNec, + Image = req.ProductImage, + Link = req.ProductLink, + MinimalQuantity = req.ProductMinimalQuantity + }; + await productsRepository.AddAsync(product, ct); + } + + // Vérifie si le prix existe déjà pour ce fournisseur et produit + var 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 Models.Price() + { + SellingPrice = req.SellingPrice, + SupplierId = supplier.Id, + ProductId = product.Id + }; + await pricesRepository.AddAsync(priceAdded, ct); + + + await Send.OkAsync(mapper.Map(priceAdded), ct); + } +} diff --git a/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs rename to PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs diff --git a/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs b/PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs rename to PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs diff --git a/PyroFetes/Repositories/DeliverersRepository.cs b/PyroFetes/Repositories/DeliverersRepository.cs index 5f2af84..0bf8c2e 100644 --- a/PyroFetes/Repositories/DeliverersRepository.cs +++ b/PyroFetes/Repositories/DeliverersRepository.cs @@ -2,4 +2,4 @@ using PyroFetes.Models; namespace PyroFetes.Repositories; -public class DeliverersRepository(PyroFetesDbContext lmdContext, AutoMapper.IMapper mapper) : PyrofetesRepository(lmdContext, mapper); +public class DeliverersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); diff --git a/PyroFetes/Repositories/PricesRepository.cs b/PyroFetes/Repositories/PricesRepository.cs new file mode 100644 index 0000000..ec33111 --- /dev/null +++ b/PyroFetes/Repositories/PricesRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class PricesRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Repositories/ProductsRepository.cs b/PyroFetes/Repositories/ProductsRepository.cs new file mode 100644 index 0000000..40719c6 --- /dev/null +++ b/PyroFetes/Repositories/ProductsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class ProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Repositories/SuppliersRepository.cs b/PyroFetes/Repositories/SuppliersRepository.cs new file mode 100644 index 0000000..1f8a8c0 --- /dev/null +++ b/PyroFetes/Repositories/SuppliersRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class SuppliersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/Prices/GetPriceByProductIdAndSupplierIdSpec.cs b/PyroFetes/Specifications/Prices/GetPriceByProductIdAndSupplierIdSpec.cs new file mode 100644 index 0000000..5f74c13 --- /dev/null +++ b/PyroFetes/Specifications/Prices/GetPriceByProductIdAndSupplierIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Prices; + +public sealed class GetPriceByProductIdAndSupplierIdSpec : Specification +{ + public GetPriceByProductIdAndSupplierIdSpec(int? productId, int? supplierId) + { + Query + .Where(p => p.ProductId == productId && p.SupplierId == supplierId); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/Products/GetProductByIdSpec.cs b/PyroFetes/Specifications/Products/GetProductByIdSpec.cs new file mode 100644 index 0000000..fb7322c --- /dev/null +++ b/PyroFetes/Specifications/Products/GetProductByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Products; + +public sealed class GetProductByIdSpec : Specification +{ + public GetProductByIdSpec(int? productId) + { + Query + .Where(p => p.Id == productId); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/Suppliers/GetSupplierByIdSpec.cs b/PyroFetes/Specifications/Suppliers/GetSupplierByIdSpec.cs new file mode 100644 index 0000000..add1699 --- /dev/null +++ b/PyroFetes/Specifications/Suppliers/GetSupplierByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Suppliers; + +public sealed class GetSupplierByIdSpec : Specification +{ + public GetSupplierByIdSpec(int? supplierId) + { + Query + .Where(x => x.Id == supplierId); + } +} \ No newline at end of file From 2385b7b687bb30320086da10425401aa3789c62d Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 13 Nov 2025 17:28:08 +0100 Subject: [PATCH 02/16] Made an update on database and added CreatingDeliveryNotee --- .../Request/CreateDeliveryNoteDto.cs | 3 +- .../CreateDeliveryNoteEndpoint.cs | 67 +++++++++++++++++++ .../GetAllProductsEndpoint.cs | 0 .../GetProductEndpoint.cs | 0 .../PatchProductMinimalStockEndpoint.cs | 0 .../UpdateProductEndpoint.cs | 0 .../PyroFetesDbContextModelSnapshot.cs | 2 +- PyroFetes/Models/DeliveryNote.cs | 2 +- .../Repositories/DeliveryNotesRepository.cs | 5 ++ .../ProductDeliveriesRepository.cs | 5 ++ 10 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs rename PyroFetes/Endpoints/{Product => Products}/GetAllProductsEndpoint.cs (100%) rename PyroFetes/Endpoints/{Product => Products}/GetProductEndpoint.cs (100%) rename PyroFetes/Endpoints/{Product => Products}/PatchProductMinimalStockEndpoint.cs (100%) rename PyroFetes/Endpoints/{Product => Products}/UpdateProductEndpoint.cs (100%) create mode 100644 PyroFetes/Repositories/DeliveryNotesRepository.cs create mode 100644 PyroFetes/Repositories/ProductDeliveriesRepository.cs diff --git a/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs b/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs index f862856..c2ee0d9 100644 --- a/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs +++ b/PyroFetes/DTO/DeliveryNote/Request/CreateDeliveryNoteDto.cs @@ -5,7 +5,8 @@ public class CreateDeliveryNoteDto public string? TrackingNumber { get; set; } public DateOnly EstimateDeliveryDate { get; set; } public DateOnly ExpeditionDate { get; set; } - public DateOnly RealDeliveryDate { get; set; } public int DelivererId { get; set; } + + public Dictionary? ProductQuantities { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..20addcd --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs @@ -0,0 +1,67 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Request; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Deliverers; +using PyroFetes.Specifications.Products; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class CreateDeliveryNoteEndpoint( + DeliveryNotesRepository deliveryNotesRepository, + DeliverersRepository deliverersRepository, + ProductsRepository productsRepository, + ProductDeliveriesRepository productDeliveriesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/DeliveryNote"); + } + + public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct) + { + Deliverer? deliverer = await deliverersRepository.FirstOrDefaultAsync(new GetDelivererByIdSpec(req.DelivererId), ct); + + if (deliverer == null) + { + await Send.StringAsync("No deliverer found", 404, cancellation: ct); + return; + } + + //Creating the Delivery Note + DeliveryNote newDeliveryNote = new DeliveryNote() + { + TrackingNumber = req.TrackingNumber, + EstimateDeliveryDate = req.EstimateDeliveryDate, + ExpeditionDate = req.ExpeditionDate, + DelivererId = req.DelivererId, + Deliverer = deliverer, + + }; + + await deliveryNotesRepository.AddAsync(newDeliveryNote, ct); + + foreach (var productQuantity in req.ProductQuantities!) + { + Models.Product? product = + await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct); + if (product != null) + { + ProductDelivery productDelivery = new ProductDelivery() + { + DeliveryNote = newDeliveryNote, + Quantity = productQuantity.Value, + Product = product, + DeliveryNoteId = newDeliveryNote.Id + }; + + await productDeliveriesRepository.AddAsync(productDelivery, ct); + } + + } + + await Send.OkAsync(mapper.Map(newDeliveryNote), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs rename to PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs diff --git a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Product/GetProductEndpoint.cs rename to PyroFetes/Endpoints/Products/GetProductEndpoint.cs diff --git a/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs rename to PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs diff --git a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs similarity index 100% rename from PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs rename to PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs diff --git a/PyroFetes/Migrations/PyroFetesDbContextModelSnapshot.cs b/PyroFetes/Migrations/PyroFetesDbContextModelSnapshot.cs index 43d8e4f..ddf13ed 100644 --- a/PyroFetes/Migrations/PyroFetesDbContextModelSnapshot.cs +++ b/PyroFetes/Migrations/PyroFetesDbContextModelSnapshot.cs @@ -326,7 +326,7 @@ namespace PyroFetes.Migrations b.Property("ExpeditionDate") .HasColumnType("date"); - b.Property("RealDeliveryDate") + b.Property("RealDeliveryDate") .HasColumnType("date"); b.Property("TrackingNumber") diff --git a/PyroFetes/Models/DeliveryNote.cs b/PyroFetes/Models/DeliveryNote.cs index 21e873e..e94792f 100644 --- a/PyroFetes/Models/DeliveryNote.cs +++ b/PyroFetes/Models/DeliveryNote.cs @@ -9,7 +9,7 @@ public class DeliveryNote public int DelivererId { get; set; } [Required] public DateOnly EstimateDeliveryDate { get; set; } [Required] public DateOnly ExpeditionDate { get; set; } - [Required] public DateOnly RealDeliveryDate { get; set; } + public DateOnly? RealDeliveryDate { get; set; } public Deliverer? Deliverer { get; set; } public List? ProductDeliveries { get; set; } diff --git a/PyroFetes/Repositories/DeliveryNotesRepository.cs b/PyroFetes/Repositories/DeliveryNotesRepository.cs new file mode 100644 index 0000000..6d87b05 --- /dev/null +++ b/PyroFetes/Repositories/DeliveryNotesRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class DeliveryNotesRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Repositories/ProductDeliveriesRepository.cs b/PyroFetes/Repositories/ProductDeliveriesRepository.cs new file mode 100644 index 0000000..376e24b --- /dev/null +++ b/PyroFetes/Repositories/ProductDeliveriesRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class ProductDeliveriesRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file From d7cf245d354ae1a7aaf1434b5e1bb87b85c08cc1 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 13 Nov 2025 17:28:41 +0100 Subject: [PATCH 03/16] Committed migration --- ...51113162655_FixedNullableValue.Designer.cs | 1963 +++++++++++++++++ .../20251113162655_FixedNullableValue.cs | 37 + 2 files changed, 2000 insertions(+) create mode 100644 PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs create mode 100644 PyroFetes/Migrations/20251113162655_FixedNullableValue.cs diff --git a/PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs b/PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs new file mode 100644 index 0000000..131aa6e --- /dev/null +++ b/PyroFetes/Migrations/20251113162655_FixedNullableValue.Designer.cs @@ -0,0 +1,1963 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using PyroFetes; + +#nullable disable + +namespace PyroFetes.Migrations +{ + [DbContext(typeof(PyroFetesDbContext))] + [Migration("20251113162655_FixedNullableValue")] + partial class FixedNullableValue + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("PyroFetes.Models.Availability", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AvailabilityDate") + .HasColumnType("date"); + + b.Property("DeliveryDate") + .HasColumnType("date"); + + b.Property("ExpirationDate") + .HasColumnType("date"); + + b.Property("RenewallDate") + .HasColumnType("date"); + + b.HasKey("Id"); + + b.ToTable("Availabilities"); + }); + + modelBuilder.Entity("PyroFetes.Models.Brand", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("Brands"); + }); + + modelBuilder.Entity("PyroFetes.Models.City", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Cities"); + }); + + modelBuilder.Entity("PyroFetes.Models.Classification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Classifications"); + }); + + modelBuilder.Entity("PyroFetes.Models.Color", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Colors"); + }); + + modelBuilder.Entity("PyroFetes.Models.Communication", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Calling") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ContactId") + .HasColumnType("int"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Meeting") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.HasKey("Id"); + + b.HasIndex("ContactId"); + + b.ToTable("Communications"); + }); + + modelBuilder.Entity("PyroFetes.Models.Contact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("Role") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Contacts"); + }); + + modelBuilder.Entity("PyroFetes.Models.ContactServiceProvider", b => + { + b.Property("ContactId") + .HasColumnType("int"); + + b.Property("ServiceProviderId") + .HasColumnType("int"); + + b.HasKey("ContactId", "ServiceProviderId"); + + b.HasIndex("ServiceProviderId"); + + b.ToTable("ContactServiceProviders"); + }); + + modelBuilder.Entity("PyroFetes.Models.Contract", b => + { + b.Property("ShowId") + .HasColumnType("int"); + + b.Property("ServiceProviderId") + .HasColumnType("int"); + + b.Property("TermsAndConditions") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("ShowId", "ServiceProviderId"); + + b.HasIndex("ServiceProviderId"); + + b.ToTable("Contracts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CustomerTypeId") + .HasColumnType("int"); + + b.Property("Note") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerTypeId"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("PyroFetes.Models.CustomerType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("CustomerTypes"); + }); + + modelBuilder.Entity("PyroFetes.Models.Deliverer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Transporter") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Deliverers"); + }); + + modelBuilder.Entity("PyroFetes.Models.DeliveryNote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DelivererId") + .HasColumnType("int"); + + b.Property("EstimateDeliveryDate") + .HasColumnType("date"); + + b.Property("ExpeditionDate") + .HasColumnType("date"); + + b.Property("RealDeliveryDate") + .HasColumnType("date"); + + b.Property("TrackingNumber") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.HasIndex("DelivererId"); + + b.ToTable("DeliveryNotes"); + }); + + modelBuilder.Entity("PyroFetes.Models.Effect", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.ToTable("Effects"); + }); + + modelBuilder.Entity("PyroFetes.Models.ExperienceLevel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("StaffId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StaffId"); + + b.ToTable("ExperienceLevels"); + }); + + modelBuilder.Entity("PyroFetes.Models.HistoryOfApproval", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DeliveryDate") + .HasColumnType("date"); + + b.Property("ExpirationDate") + .HasColumnType("date"); + + b.HasKey("Id"); + + b.ToTable("HistoryOfApprovals"); + }); + + modelBuilder.Entity("PyroFetes.Models.Material", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("WarehouseId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("WarehouseId"); + + b.ToTable("Materials"); + }); + + modelBuilder.Entity("PyroFetes.Models.MaterialWarehouse", b => + { + b.Property("MaterialId") + .HasColumnType("int"); + + b.Property("WarehouseId") + .HasColumnType("int"); + + b.HasKey("MaterialId", "WarehouseId"); + + b.HasIndex("WarehouseId"); + + b.ToTable("MaterialWarehouses"); + }); + + modelBuilder.Entity("PyroFetes.Models.Movement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Arrival") + .HasColumnType("datetime2"); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("DestinationWarehouseId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.Property("SourceWarehouseId") + .HasColumnType("int"); + + b.Property("Start") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.HasIndex("DestinationWarehouseId"); + + b.HasIndex("SourceWarehouseId"); + + b.ToTable("Movements"); + }); + + modelBuilder.Entity("PyroFetes.Models.Price", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("SupplierId") + .HasColumnType("int"); + + b.Property("SellingPrice") + .HasColumnType("decimal(18,2)"); + + b.HasKey("ProductId", "SupplierId"); + + b.HasIndex("SupplierId"); + + b.ToTable("Prices"); + }); + + modelBuilder.Entity("PyroFetes.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ApprovalNumber") + .HasColumnType("int"); + + b.Property("Caliber") + .HasColumnType("decimal(18,2)"); + + b.Property("ClassificationId") + .HasColumnType("int"); + + b.Property("Duration") + .HasColumnType("decimal(18,2)"); + + b.Property("Image") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Link") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.Property("MinimalQuantity") + .HasColumnType("int"); + + b.Property("MovementId") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Nec") + .HasColumnType("decimal(18,2)"); + + b.Property("ProductCategoryId") + .HasColumnType("int"); + + b.Property("Reference") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("nvarchar(20)"); + + b.Property("Weight") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("ClassificationId"); + + b.HasIndex("MovementId"); + + b.HasIndex("ProductCategoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("ProductCategories"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductColor", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("ColorId") + .HasColumnType("int"); + + b.HasKey("ProductId", "ColorId"); + + b.HasIndex("ColorId"); + + b.ToTable("ProductColors"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductDelivery", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("DeliveryNoteId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("ProductId", "DeliveryNoteId"); + + b.HasIndex("DeliveryNoteId"); + + b.ToTable("ProductDeliveries"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductEffect", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("EffectId") + .HasColumnType("int"); + + b.HasKey("ProductId", "EffectId"); + + b.HasIndex("EffectId"); + + b.ToTable("ProductEffects"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductTimecode", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("ShowId") + .HasColumnType("int"); + + b.Property("End") + .HasColumnType("decimal(18,2)"); + + b.Property("Start") + .HasColumnType("decimal(18,2)"); + + b.HasKey("ProductId", "ShowId"); + + b.HasIndex("ShowId"); + + b.ToTable("ProductTimecodes"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProviderContact", b => + { + b.Property("ContactId") + .HasColumnType("int"); + + b.Property("ProviderId") + .HasColumnType("int"); + + b.HasKey("ContactId", "ProviderId"); + + b.HasIndex("ProviderId"); + + b.ToTable("ProviderContacts"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProviderType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("ProviderTypes"); + }); + + modelBuilder.Entity("PyroFetes.Models.PurchaseOrder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PurchaseConditions") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.HasKey("Id"); + + b.ToTable("PurchaseOrders"); + }); + + modelBuilder.Entity("PyroFetes.Models.PurchaseProduct", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("PurchaseOrderId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("ProductId", "PurchaseOrderId"); + + b.HasIndex("PurchaseOrderId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Quotation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ConditionsSale") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("nvarchar(300)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("nvarchar(200)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("Quotations"); + }); + + modelBuilder.Entity("PyroFetes.Models.QuotationProduct", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("QuotationId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("ProductId", "QuotationId"); + + b.HasIndex("QuotationId"); + + b.ToTable("QuotationProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.ServiceProvider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.Property("ProviderTypeId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ProviderTypeId"); + + b.ToTable("ServiceProviders"); + }); + + modelBuilder.Entity("PyroFetes.Models.Setting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ElectronicSignature") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Logo") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Settings"); + }); + + modelBuilder.Entity("PyroFetes.Models.Show", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CityId") + .HasColumnType("int"); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Description") + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Place") + .IsRequired() + .HasMaxLength(120) + .HasColumnType("nvarchar(120)"); + + b.Property("PyrotechnicImplementationPlan") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("nvarchar(500)"); + + b.HasKey("Id"); + + b.HasIndex("CityId"); + + b.ToTable("Shows"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowMaterial", b => + { + b.Property("ShowId") + .HasColumnType("int"); + + b.Property("MaterialId") + .HasColumnType("int"); + + b.HasKey("ShowId", "MaterialId"); + + b.HasIndex("MaterialId"); + + b.ToTable("ShowMaterials"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowServiceProvider", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.HasKey("Id"); + + b.ToTable("ShowServiceProviders"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowStaff", b => + { + b.Property("StaffId") + .HasColumnType("int"); + + b.Property("ShowId") + .HasColumnType("int"); + + b.HasKey("StaffId", "ShowId"); + + b.HasIndex("ShowId"); + + b.ToTable("ShowStaffs"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowTruck", b => + { + b.Property("ShowId") + .HasColumnType("int"); + + b.Property("TruckId") + .HasColumnType("int"); + + b.HasKey("ShowId", "TruckId"); + + b.HasIndex("TruckId"); + + b.ToTable("ShowTrucks"); + }); + + modelBuilder.Entity("PyroFetes.Models.Sound", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Artist") + .IsRequired() + .HasMaxLength(120) + .HasColumnType("nvarchar(120)"); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Duration") + .IsRequired() + .HasColumnType("int"); + + b.Property("Format") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Kind") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(120) + .HasColumnType("nvarchar(120)"); + + b.Property("SoundCategoryId") + .HasColumnType("int"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.HasKey("Id"); + + b.HasIndex("SoundCategoryId"); + + b.ToTable("Sounds"); + }); + + modelBuilder.Entity("PyroFetes.Models.SoundCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("SoundCategories"); + }); + + modelBuilder.Entity("PyroFetes.Models.SoundTimecode", b => + { + b.Property("ShowId") + .HasColumnType("int"); + + b.Property("SoundId") + .HasColumnType("int"); + + b.Property("End") + .HasColumnType("decimal(18,2)"); + + b.Property("Start") + .HasColumnType("decimal(18,2)"); + + b.HasKey("ShowId", "SoundId"); + + b.HasIndex("SoundId"); + + b.ToTable("SoundTimecodes"); + }); + + modelBuilder.Entity("PyroFetes.Models.Staff", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasMaxLength(120) + .HasColumnType("nvarchar(120)"); + + b.Property("F4T2ExpirationDate") + .HasColumnType("date"); + + b.Property("F4T2NumberApproval") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("LastName") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("Profession") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Staffs"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffAvailability", b => + { + b.Property("AvailabilityId") + .HasColumnType("int"); + + b.Property("StaffId") + .HasColumnType("int"); + + b.HasKey("AvailabilityId", "StaffId"); + + b.HasIndex("StaffId"); + + b.ToTable("StaffAvailabilities"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffContact", b => + { + b.Property("ContactId") + .HasColumnType("int"); + + b.Property("StaffId") + .HasColumnType("int"); + + b.HasKey("ContactId", "StaffId"); + + b.HasIndex("StaffId"); + + b.ToTable("StaffContacts"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffHistoryOfApproval", b => + { + b.Property("HistoryOfApprovalId") + .HasColumnType("int"); + + b.Property("StaffId") + .HasColumnType("int"); + + b.HasKey("HistoryOfApprovalId", "StaffId"); + + b.HasIndex("StaffId"); + + b.ToTable("StaffHistoryOfApprovals"); + }); + + modelBuilder.Entity("PyroFetes.Models.Supplier", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("DeliveryDelay") + .HasColumnType("int"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Phone") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("nvarchar(30)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Suppliers"); + }); + + modelBuilder.Entity("PyroFetes.Models.Truck", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("MaxExplosiveCapacity") + .IsRequired() + .HasColumnType("float"); + + b.Property("Sizes") + .IsRequired() + .HasMaxLength(80) + .HasColumnType("nvarchar(80)"); + + b.Property("Status") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.Property("Type") + .IsRequired() + .HasMaxLength(40) + .HasColumnType("nvarchar(40)"); + + b.HasKey("Id"); + + b.ToTable("Trucks"); + }); + + modelBuilder.Entity("PyroFetes.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Fonction") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Salt") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("PyroFetes.Models.Warehouse", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("City") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Current") + .HasColumnType("int"); + + b.Property("MaxWeight") + .HasColumnType("int"); + + b.Property("MinWeight") + .HasColumnType("int"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("ZipCode") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Warehouses"); + }); + + modelBuilder.Entity("PyroFetes.Models.WarehouseProduct", b => + { + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("WarehouseId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("ProductId", "WarehouseId"); + + b.HasIndex("WarehouseId"); + + b.ToTable("WarehouseProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Brand", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("Brands") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("PyroFetes.Models.Communication", b => + { + b.HasOne("PyroFetes.Models.Contact", "Contact") + .WithMany("Communications") + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contact"); + }); + + modelBuilder.Entity("PyroFetes.Models.Contact", b => + { + b.HasOne("PyroFetes.Models.Customer", "Customer") + .WithMany("Contacts") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("PyroFetes.Models.ContactServiceProvider", b => + { + b.HasOne("PyroFetes.Models.Contact", "Contact") + .WithMany("ContactServiceProviders") + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.ServiceProvider", "ServiceProvider") + .WithMany("ContactServiceProviders") + .HasForeignKey("ServiceProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contact"); + + b.Navigation("ServiceProvider"); + }); + + modelBuilder.Entity("PyroFetes.Models.Contract", b => + { + b.HasOne("PyroFetes.Models.ServiceProvider", "ServiceProvider") + .WithMany("Contracts") + .HasForeignKey("ServiceProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("Contracts") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ServiceProvider"); + + b.Navigation("Show"); + }); + + modelBuilder.Entity("PyroFetes.Models.Customer", b => + { + b.HasOne("PyroFetes.Models.CustomerType", "CustomerType") + .WithMany("Customers") + .HasForeignKey("CustomerTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("CustomerType"); + }); + + modelBuilder.Entity("PyroFetes.Models.DeliveryNote", b => + { + b.HasOne("PyroFetes.Models.Deliverer", "Deliverer") + .WithMany("DeliveryNotes") + .HasForeignKey("DelivererId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Deliverer"); + }); + + modelBuilder.Entity("PyroFetes.Models.ExperienceLevel", b => + { + b.HasOne("PyroFetes.Models.Staff", "Staff") + .WithMany("ExperienceLevels") + .HasForeignKey("StaffId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("PyroFetes.Models.Material", b => + { + b.HasOne("PyroFetes.Models.Warehouse", "Warehouse") + .WithMany() + .HasForeignKey("WarehouseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Warehouse"); + }); + + modelBuilder.Entity("PyroFetes.Models.MaterialWarehouse", b => + { + b.HasOne("PyroFetes.Models.Material", "Material") + .WithMany("MaterialWarehouses") + .HasForeignKey("MaterialId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Warehouse", "Warehouse") + .WithMany("MaterialWarehouses") + .HasForeignKey("WarehouseId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Material"); + + b.Navigation("Warehouse"); + }); + + modelBuilder.Entity("PyroFetes.Models.Movement", b => + { + b.HasOne("PyroFetes.Models.Warehouse", "DestinationWarehouse") + .WithMany("MovementsDestination") + .HasForeignKey("DestinationWarehouseId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("PyroFetes.Models.Warehouse", "SourceWarehouse") + .WithMany("MovementsSource") + .HasForeignKey("SourceWarehouseId") + .OnDelete(DeleteBehavior.Restrict); + + b.Navigation("DestinationWarehouse"); + + b.Navigation("SourceWarehouse"); + }); + + modelBuilder.Entity("PyroFetes.Models.Price", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("Prices") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Supplier", "Supplier") + .WithMany("Prices") + .HasForeignKey("SupplierId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Supplier"); + }); + + modelBuilder.Entity("PyroFetes.Models.Product", b => + { + b.HasOne("PyroFetes.Models.Classification", "Classification") + .WithMany("Products") + .HasForeignKey("ClassificationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Movement", "Movement") + .WithMany("Products") + .HasForeignKey("MovementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.ProductCategory", "ProductCategory") + .WithMany("Products") + .HasForeignKey("ProductCategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Classification"); + + b.Navigation("Movement"); + + b.Navigation("ProductCategory"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductColor", b => + { + b.HasOne("PyroFetes.Models.Color", "Color") + .WithMany("ProductColors") + .HasForeignKey("ColorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("ProductColors") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Color"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductDelivery", b => + { + b.HasOne("PyroFetes.Models.DeliveryNote", "DeliveryNote") + .WithMany("ProductDeliveries") + .HasForeignKey("DeliveryNoteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("ProductDeliveries") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("DeliveryNote"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductEffect", b => + { + b.HasOne("PyroFetes.Models.Effect", "Effect") + .WithMany("ProductEffects") + .HasForeignKey("EffectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("ProductEffects") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Effect"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductTimecode", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("ProductTimecodes") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("ProductTimecodes") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Show"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProviderContact", b => + { + b.HasOne("PyroFetes.Models.Contact", "Contact") + .WithMany() + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.ServiceProvider", "Provider") + .WithMany() + .HasForeignKey("ProviderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contact"); + + b.Navigation("Provider"); + }); + + modelBuilder.Entity("PyroFetes.Models.PurchaseProduct", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("PurchaseProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.PurchaseOrder", "PurchaseOrder") + .WithMany("PurchaseProducts") + .HasForeignKey("PurchaseOrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("PurchaseOrder"); + }); + + modelBuilder.Entity("PyroFetes.Models.Quotation", b => + { + b.HasOne("PyroFetes.Models.Customer", "Customer") + .WithMany("Quotations") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("PyroFetes.Models.QuotationProduct", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("QuotationProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Quotation", "Quotation") + .WithMany("QuotationProducts") + .HasForeignKey("QuotationId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Quotation"); + }); + + modelBuilder.Entity("PyroFetes.Models.ServiceProvider", b => + { + b.HasOne("PyroFetes.Models.ProviderType", "ProviderType") + .WithMany("ServiceProviders") + .HasForeignKey("ProviderTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ProviderType"); + }); + + modelBuilder.Entity("PyroFetes.Models.Show", b => + { + b.HasOne("PyroFetes.Models.City", "City") + .WithMany("Shows") + .HasForeignKey("CityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("City"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowMaterial", b => + { + b.HasOne("PyroFetes.Models.Material", "Material") + .WithMany("ShowMaterials") + .HasForeignKey("MaterialId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("ShowMaterials") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Material"); + + b.Navigation("Show"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowStaff", b => + { + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("ShowStaffs") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Staff", "Staff") + .WithMany("ShowStaffs") + .HasForeignKey("StaffId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Show"); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("PyroFetes.Models.ShowTruck", b => + { + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("ShowTrucks") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Truck", "Truck") + .WithMany("ShowTrucks") + .HasForeignKey("TruckId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Show"); + + b.Navigation("Truck"); + }); + + modelBuilder.Entity("PyroFetes.Models.Sound", b => + { + b.HasOne("PyroFetes.Models.SoundCategory", "SoundCategory") + .WithMany("Sounds") + .HasForeignKey("SoundCategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SoundCategory"); + }); + + modelBuilder.Entity("PyroFetes.Models.SoundTimecode", b => + { + b.HasOne("PyroFetes.Models.Show", "Show") + .WithMany("SoundTimecodes") + .HasForeignKey("ShowId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Sound", "Sound") + .WithMany("SoundTimecodes") + .HasForeignKey("SoundId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Show"); + + b.Navigation("Sound"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffAvailability", b => + { + b.HasOne("PyroFetes.Models.Availability", "Availability") + .WithMany("StaffAvailabilities") + .HasForeignKey("AvailabilityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Staff", "Staff") + .WithMany("StaffAvailabilities") + .HasForeignKey("StaffId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Availability"); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffContact", b => + { + b.HasOne("PyroFetes.Models.Contact", "Contact") + .WithMany("StaffContacts") + .HasForeignKey("ContactId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Staff", "Staff") + .WithMany("StaffContacts") + .HasForeignKey("StaffId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Contact"); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("PyroFetes.Models.StaffHistoryOfApproval", b => + { + b.HasOne("PyroFetes.Models.HistoryOfApproval", "HistoryOfApproval") + .WithMany("StaffHistoryOfApprovals") + .HasForeignKey("HistoryOfApprovalId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Staff", "Staff") + .WithMany("StaffHistoryOfApprovals") + .HasForeignKey("StaffId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("HistoryOfApproval"); + + b.Navigation("Staff"); + }); + + modelBuilder.Entity("PyroFetes.Models.WarehouseProduct", b => + { + b.HasOne("PyroFetes.Models.Product", "Product") + .WithMany("WarehouseProducts") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("PyroFetes.Models.Warehouse", "Warehouse") + .WithMany("WarehouseProducts") + .HasForeignKey("WarehouseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Warehouse"); + }); + + modelBuilder.Entity("PyroFetes.Models.Availability", b => + { + b.Navigation("StaffAvailabilities"); + }); + + modelBuilder.Entity("PyroFetes.Models.City", b => + { + b.Navigation("Shows"); + }); + + modelBuilder.Entity("PyroFetes.Models.Classification", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("PyroFetes.Models.Color", b => + { + b.Navigation("ProductColors"); + }); + + modelBuilder.Entity("PyroFetes.Models.Contact", b => + { + b.Navigation("Communications"); + + b.Navigation("ContactServiceProviders"); + + b.Navigation("StaffContacts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Customer", b => + { + b.Navigation("Contacts"); + + b.Navigation("Quotations"); + }); + + modelBuilder.Entity("PyroFetes.Models.CustomerType", b => + { + b.Navigation("Customers"); + }); + + modelBuilder.Entity("PyroFetes.Models.Deliverer", b => + { + b.Navigation("DeliveryNotes"); + }); + + modelBuilder.Entity("PyroFetes.Models.DeliveryNote", b => + { + b.Navigation("ProductDeliveries"); + }); + + modelBuilder.Entity("PyroFetes.Models.Effect", b => + { + b.Navigation("ProductEffects"); + }); + + modelBuilder.Entity("PyroFetes.Models.HistoryOfApproval", b => + { + b.Navigation("StaffHistoryOfApprovals"); + }); + + modelBuilder.Entity("PyroFetes.Models.Material", b => + { + b.Navigation("MaterialWarehouses"); + + b.Navigation("ShowMaterials"); + }); + + modelBuilder.Entity("PyroFetes.Models.Movement", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("PyroFetes.Models.Product", b => + { + b.Navigation("Brands"); + + b.Navigation("Prices"); + + b.Navigation("ProductColors"); + + b.Navigation("ProductDeliveries"); + + b.Navigation("ProductEffects"); + + b.Navigation("ProductTimecodes"); + + b.Navigation("PurchaseProducts"); + + b.Navigation("QuotationProducts"); + + b.Navigation("WarehouseProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProductCategory", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("PyroFetes.Models.ProviderType", b => + { + b.Navigation("ServiceProviders"); + }); + + modelBuilder.Entity("PyroFetes.Models.PurchaseOrder", b => + { + b.Navigation("PurchaseProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Quotation", b => + { + b.Navigation("QuotationProducts"); + }); + + modelBuilder.Entity("PyroFetes.Models.ServiceProvider", b => + { + b.Navigation("ContactServiceProviders"); + + b.Navigation("Contracts"); + }); + + modelBuilder.Entity("PyroFetes.Models.Show", b => + { + b.Navigation("Contracts"); + + b.Navigation("ProductTimecodes"); + + b.Navigation("ShowMaterials"); + + b.Navigation("ShowStaffs"); + + b.Navigation("ShowTrucks"); + + b.Navigation("SoundTimecodes"); + }); + + modelBuilder.Entity("PyroFetes.Models.Sound", b => + { + b.Navigation("SoundTimecodes"); + }); + + modelBuilder.Entity("PyroFetes.Models.SoundCategory", b => + { + b.Navigation("Sounds"); + }); + + modelBuilder.Entity("PyroFetes.Models.Staff", b => + { + b.Navigation("ExperienceLevels"); + + b.Navigation("ShowStaffs"); + + b.Navigation("StaffAvailabilities"); + + b.Navigation("StaffContacts"); + + b.Navigation("StaffHistoryOfApprovals"); + }); + + modelBuilder.Entity("PyroFetes.Models.Supplier", b => + { + b.Navigation("Prices"); + }); + + modelBuilder.Entity("PyroFetes.Models.Truck", b => + { + b.Navigation("ShowTrucks"); + }); + + modelBuilder.Entity("PyroFetes.Models.Warehouse", b => + { + b.Navigation("MaterialWarehouses"); + + b.Navigation("MovementsDestination"); + + b.Navigation("MovementsSource"); + + b.Navigation("WarehouseProducts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/PyroFetes/Migrations/20251113162655_FixedNullableValue.cs b/PyroFetes/Migrations/20251113162655_FixedNullableValue.cs new file mode 100644 index 0000000..0fe6098 --- /dev/null +++ b/PyroFetes/Migrations/20251113162655_FixedNullableValue.cs @@ -0,0 +1,37 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace PyroFetes.Migrations +{ + /// + public partial class FixedNullableValue : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "RealDeliveryDate", + table: "DeliveryNotes", + type: "date", + nullable: true, + oldClrType: typeof(DateOnly), + oldType: "date"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "RealDeliveryDate", + table: "DeliveryNotes", + type: "date", + nullable: false, + defaultValue: new DateOnly(1, 1, 1), + oldClrType: typeof(DateOnly), + oldType: "date", + oldNullable: true); + } + } +} From 20bbccf8839703872f06e9635f909b8622b02a14 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Fri, 14 Nov 2025 18:11:54 +0100 Subject: [PATCH 04/16] Added last endpoints for delivery Note --- .../DTO/Supplier/Request/CreateSupplierDto.cs | 2 +- .../DTO/Supplier/Request/UpdateSupplierDto.cs | 2 +- .../GetAllDeliveryNoteEndpoint.cs | 20 ++++++++++ .../DeliveryNotes/GetDeliveryNoteEndpoint.cs | 35 +++++++++++++++++ .../PatchRealDeliveryDateEndpoint.cs | 39 +++++++++++++++++++ PyroFetes/Models/Supplier.cs | 2 +- .../DeliveryNotes/GetDeliveryNoteByIdSpec.cs | 13 +++++++ 7 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs create mode 100644 PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs create mode 100644 PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs create mode 100644 PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs diff --git a/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs b/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs index b9e9fe0..649ef2b 100644 --- a/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs +++ b/PyroFetes/DTO/Supplier/Request/CreateSupplierDto.cs @@ -6,7 +6,7 @@ public class CreateSupplierDto public string? Email { get; set; } public string? Phone { get; set; } public string? Address { get; set; } - public int ZipCode { get; set; } + public string? ZipCode { get; set; } public string? City { get; set; } public int DeliveryDelay { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs b/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs index b69b72b..0deefef 100644 --- a/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs +++ b/PyroFetes/DTO/Supplier/Request/UpdateSupplierDto.cs @@ -7,7 +7,7 @@ public class UpdateSupplierDto public string? Email { get; set; } public string? Phone { get; set; } public string? Address { get; set; } - public int ZipCode { get; set; } + public string? ZipCode { get; set; } public string? City { get; set; } public int DeliveryDelay { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..879b7b6 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/GetAllDeliveryNoteEndpoint.cs @@ -0,0 +1,20 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class GetAllDeliveryNoteEndpoint(DeliveryNotesRepository deliveryNotesRepository) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("api/deliveryNotes"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken ct) + { + await Send.OkAsync(await deliveryNotesRepository.ProjectToListAsync(ct), ct); + } + +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs new file mode 100644 index 0000000..98eb447 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/GetDeliveryNoteEndpoint.cs @@ -0,0 +1,35 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.DeliveryNotes; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class GetDeliveryNoteRequest +{ + public int DeliveryNoteId { get; set; } +} +public class GetDeliveryNoteEndpoint( + DeliveryNotesRepository deliveryNotesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/deliveryNote/{@id}", x=> new {x.DeliveryNoteId}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetDeliveryNoteRequest req, CancellationToken ct) + { + DeliveryNote? deliveryNote = await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.DeliveryNoteId), ct); + + if (deliveryNote == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await Send.OkAsync(mapper.Map(deliveryNote), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs new file mode 100644 index 0000000..d47d639 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/PatchRealDeliveryDateEndpoint.cs @@ -0,0 +1,39 @@ +using FastEndpoints; +using PyroFetes.DTO.DeliveryNote.Request; +using PyroFetes.DTO.DeliveryNote.Response; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Deliverers; +using PyroFetes.Specifications.DeliveryNotes; + +namespace PyroFetes.Endpoints.DeliveryNotes; + +public class PatchRealDeliveryDateEndpoint( + DeliveryNotesRepository deliveryNotesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/deliveryNote/{@id}", x=> new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchDeliveryNoteRealDeliveryDateDto req, CancellationToken ct) + { + DeliveryNote? deliveryNoteToPath = + await deliveryNotesRepository.FirstOrDefaultAsync(new GetDeliveryNoteByIdSpec(req.Id),ct); + + if (deliveryNoteToPath == null) + { + await Send.NotFoundAsync(ct); + return; + } + + deliveryNoteToPath.RealDeliveryDate = req.RealDeliveryDate; + + await deliveryNotesRepository.UpdateAsync(deliveryNoteToPath, ct); + + await Send.OkAsync(mapper.Map(deliveryNoteToPath), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Models/Supplier.cs b/PyroFetes/Models/Supplier.cs index f131804..4e02663 100644 --- a/PyroFetes/Models/Supplier.cs +++ b/PyroFetes/Models/Supplier.cs @@ -9,7 +9,7 @@ public class Supplier [Required, MaxLength(100)] public string? Email { get; set; } [Required, MaxLength(30)] public string? Phone { get; set; } [Required, MaxLength(100)] public string? Address { get; set; } - [Required] public int ZipCode { get; set; } + [Required,MaxLength(5),MinLength(5)] public string? ZipCode { get; set; } [Required, MaxLength(100)] public string? City { get; set; } [Required] public int DeliveryDelay { get; set; } diff --git a/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs b/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs new file mode 100644 index 0000000..2fc0494 --- /dev/null +++ b/PyroFetes/Specifications/DeliveryNotes/GetDeliveryNoteByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.DeliveryNotes; + +public sealed class GetDeliveryNoteByIdSpec : Specification +{ + public GetDeliveryNoteByIdSpec(int deliveryNoteId) + { + Query + .Where(x => x.Id == deliveryNoteId); + } +} \ No newline at end of file From 6dba61f742f9fbe488d829c595fbaac4313d2b2f Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Mon, 17 Nov 2025 20:49:12 +0100 Subject: [PATCH 05/16] suppr all 'var' and Models.xxx. And added 's' at the end of all directories endpoints --- PyroFetes/DTO/Price/Request/CreatePriceDto.cs | 2 +- PyroFetes/DTO/Supplier/Response/GetSupplierDto.cs | 2 +- .../Deliverers/CreateDelivererEndpoint.cs | 1 - .../DeliveryNotes/CreateDeliveryNoteEndpoint.cs | 2 +- PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs | 13 +++++++------ PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs | 5 +++-- PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs | 5 +++-- .../Endpoints/Products/GetAllProductsEndpoint.cs | 6 +++--- .../Endpoints/Products/GetProductEndpoint.cs | 6 +++--- .../Products/PatchProductMinimalStockEndpoint.cs | 6 +++--- .../Endpoints/Products/UpdateProductEndpoint.cs | 5 +++-- .../DeletePurchaseOrderEndpoint.cs | 5 +++-- .../GetAllPurchaseOrderEndpoint.cs | 4 ++-- .../GetPurchaseOrderEndpoint.cs | 5 +++-- ...atchPurchaseOrderPurchaseConditionsEndpoint.cs | 6 +++--- .../CreatePurchaseProductEndpoint.cs | 15 ++++++++------- .../DeletePurchaseProductEndpoint.cs | 5 +++-- .../PatchPurchaseProductQuantityEndpoint.cs | 5 +++-- .../CreateQuotationProductEndpoint.cs | 13 +++++++------ .../DeleteQuotationProductEndpoint.cs | 5 +++-- .../PatchQuotationProductQuantityEndpoint.cs | 5 +++-- .../DeleteQuotationEndpoint.cs | 5 +++-- .../GetAllQuotationEndpoint.cs | 5 +++-- .../GetQuotationEndpoint.cs | 5 +++-- .../PatchQuotationConditionsSaleEndpoint.cs | 8 +++----- .../CreateSettingEndpoint.cs | 5 +++-- .../DeleteSettingEndpoint.cs | 5 +++-- .../GetSettingEndpoint.cs | 5 +++-- .../PatchSettingElectronicSignatureEndpoint.cs | 5 +++-- .../PatchSettingLogoEndpoint.cs | 5 +++-- .../CreateSupplierEndpoint.cs | 9 +++++---- .../DeleteSupplierEndpoint.cs | 5 +++-- .../GetAllSuppliersEndpoint.cs | 5 ++--- .../GetSupplierEndpoint.cs | 5 +++-- .../PatchSupplierDeleveryDelayEndpoint.cs | 5 +++-- .../UpdateSupplierEndpoint.cs | 5 +++-- .../{User => Users}/ConnectUserEndpoint.cs | 7 ++++--- .../{User => Users}/CreateUserEndpoint.cs | 5 +++-- .../{User => Users}/DeleteUserEndpoint.cs | 5 +++-- .../{User => Users}/GetAllUsersEndpoint.cs | 4 ++-- .../Endpoints/{User => Users}/GetUserEndpoint.cs | 5 +++-- .../{User => Users}/PatchUserPasswordEndpoint.cs | 5 +++-- .../{User => Users}/UpdateUserEndpoint.cs | 7 ++++--- .../GetTotalQuantityEndpoint.cs | 7 ++++--- .../PatchWareHouseProductQuantityEndpoint.cs | 7 +++---- 45 files changed, 141 insertions(+), 114 deletions(-) rename PyroFetes/Endpoints/{PurchaseOrder => PurchaseOrders}/DeletePurchaseOrderEndpoint.cs (88%) rename PyroFetes/Endpoints/{PurchaseOrder => PurchaseOrders}/GetAllPurchaseOrderEndpoint.cs (93%) rename PyroFetes/Endpoints/{PurchaseOrder => PurchaseOrders}/GetPurchaseOrderEndpoint.cs (92%) rename PyroFetes/Endpoints/{PurchaseOrder => PurchaseOrders}/PatchPurchaseOrderPurchaseConditionsEndpoint.cs (90%) rename PyroFetes/Endpoints/{PurchaseProduct => PurchaseProducts}/CreatePurchaseProductEndpoint.cs (79%) rename PyroFetes/Endpoints/{PurchaseProduct => PurchaseProducts}/DeletePurchaseProductEndpoint.cs (87%) rename PyroFetes/Endpoints/{PurchaseProduct => PurchaseProducts}/PatchPurchaseProductQuantityEndpoint.cs (81%) rename PyroFetes/Endpoints/{QuotationProduct => QuotationProducts}/CreateQuotationProductEndpoint.cs (80%) rename PyroFetes/Endpoints/{QuotationProduct => QuotationProducts}/DeleteQuotationProductEndpoint.cs (86%) rename PyroFetes/Endpoints/{QuotationProduct => QuotationProducts}/PatchQuotationProductQuantityEndpoint.cs (81%) rename PyroFetes/Endpoints/{Quotation => Quotations}/DeleteQuotationEndpoint.cs (89%) rename PyroFetes/Endpoints/{Quotation => Quotations}/GetAllQuotationEndpoint.cs (92%) rename PyroFetes/Endpoints/{Quotation => Quotations}/GetQuotationEndpoint.cs (93%) rename PyroFetes/Endpoints/{Quotation => Quotations}/PatchQuotationConditionsSaleEndpoint.cs (88%) rename PyroFetes/Endpoints/{SettingEndpoints => Settings}/CreateSettingEndpoint.cs (88%) rename PyroFetes/Endpoints/{SettingEndpoints => Settings}/DeleteSettingEndpoint.cs (81%) rename PyroFetes/Endpoints/{SettingEndpoints => Settings}/GetSettingEndpoint.cs (88%) rename PyroFetes/Endpoints/{SettingEndpoints => Settings}/PatchSettingElectronicSignatureEndpoint.cs (86%) rename PyroFetes/Endpoints/{SettingEndpoints => Settings}/PatchSettingLogoEndpoint.cs (84%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/CreateSupplierEndpoint.cs (86%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/DeleteSupplierEndpoint.cs (81%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/GetAllSuppliersEndpoint.cs (86%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/GetSupplierEndpoint.cs (90%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/PatchSupplierDeleveryDelayEndpoint.cs (84%) rename PyroFetes/Endpoints/{Supplier => Suppliers}/UpdateSupplierEndpoint.cs (88%) rename PyroFetes/Endpoints/{User => Users}/ConnectUserEndpoint.cs (86%) rename PyroFetes/Endpoints/{User => Users}/CreateUserEndpoint.cs (92%) rename PyroFetes/Endpoints/{User => Users}/DeleteUserEndpoint.cs (81%) rename PyroFetes/Endpoints/{User => Users}/GetAllUsersEndpoint.cs (88%) rename PyroFetes/Endpoints/{User => Users}/GetUserEndpoint.cs (90%) rename PyroFetes/Endpoints/{User => Users}/PatchUserPasswordEndpoint.cs (87%) rename PyroFetes/Endpoints/{User => Users}/UpdateUserEndpoint.cs (85%) rename PyroFetes/Endpoints/{WareHouseProduct => WareHouseProducts}/GetTotalQuantityEndpoint.cs (84%) rename PyroFetes/Endpoints/{WareHouseProduct => WareHouseProducts}/PatchWareHouseProductQuantityEndpoint.cs (78%) diff --git a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs index b149ef6..dc4f9b2 100644 --- a/PyroFetes/DTO/Price/Request/CreatePriceDto.cs +++ b/PyroFetes/DTO/Price/Request/CreatePriceDto.cs @@ -9,7 +9,7 @@ public class CreatePriceDto public string? SupplierEmail { get; set; } public string? SupplierPhone { get; set; } public string? SupplierAddress { get; set; } - public int SupplierZipCode { get; set; } + public string? SupplierZipCode { get; set; } public string? SupplierCity { get; set; } public int SupplierDeliveryDelay { get; set; } diff --git a/PyroFetes/DTO/Supplier/Response/GetSupplierDto.cs b/PyroFetes/DTO/Supplier/Response/GetSupplierDto.cs index 7390854..1fc9a60 100644 --- a/PyroFetes/DTO/Supplier/Response/GetSupplierDto.cs +++ b/PyroFetes/DTO/Supplier/Response/GetSupplierDto.cs @@ -7,7 +7,7 @@ public class GetSupplierDto public string? Email { get; set; } public string? Phone { get; set; } public string? Address { get; set; } - public int ZipCode { get; set; } + public string? ZipCode { get; set; } public string? City { get; set; } public int DeliveryDelay { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs b/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs index 8661c64..16502ac 100644 --- a/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs +++ b/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs @@ -14,7 +14,6 @@ public class CreateDelivererEndpoint( { Post("api/deliverers"); AllowAnonymous(); - } public override async Task HandleAsync(CreateDelivererDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs index 20addcd..bc7a44a 100644 --- a/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs +++ b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs @@ -45,7 +45,7 @@ public class CreateDeliveryNoteEndpoint( foreach (var productQuantity in req.ProductQuantities!) { - Models.Product? product = + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(productQuantity.Key), ct); if (product != null) { diff --git a/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs index fcdbde3..3a71e9c 100644 --- a/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs @@ -1,6 +1,7 @@ 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; @@ -23,10 +24,10 @@ public class CreatePriceEndpoint( public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct) { // Gestion du fournisseur - var supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct); + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct); if (supplier == null) { - supplier = new Models.Supplier() + supplier = new Supplier() { Name = req.SupplierName, Email = req.SupplierEmail, @@ -40,10 +41,10 @@ public class CreatePriceEndpoint( } // Gestion du produit - var product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); if (product == null) { - product = new Models.Product() + product = new Product() { Reference = req.ProductReferences, Name = req.ProductName, @@ -60,7 +61,7 @@ public class CreatePriceEndpoint( } // Vérifie si le prix existe déjà pour ce fournisseur et produit - var existingPrice = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct); + Price? existingPrice = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct); if (existingPrice != null) { @@ -69,7 +70,7 @@ public class CreatePriceEndpoint( } // Création du prix - var priceAdded = new Models.Price() + var priceAdded = new Price() { SellingPrice = req.SellingPrice, SupplierId = supplier.Id, diff --git a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs index bb289c9..deb47e0 100644 --- a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs @@ -1,7 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.Prices; public class DeletePriceRequest { @@ -19,7 +20,7 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); if (price == null) diff --git a/PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs b/PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs index 05dbdb8..b0a9084 100644 --- a/PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/PatchPriceEndpoint.cs @@ -2,8 +2,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Price.Request; using PyroFetes.DTO.Price.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Price; +namespace PyroFetes.Endpoints.Prices; public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,7 +16,7 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + Price? price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); if (price == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs index 70ec082..e0d13d8 100644 --- a/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs +++ b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs @@ -1,9 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Product; +namespace PyroFetes.Endpoints.Products; public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { @@ -14,7 +14,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWitho public override async Task HandleAsync(CancellationToken ct) { - var product = await database.Products + List product = await database.Products .Select(product => new GetProductDto() { Id = product.Id, diff --git a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs index 72e3fa5..2125a9c 100644 --- a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs @@ -1,9 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Product; +namespace PyroFetes.Endpoints.Products; public class GetProductRequest { @@ -19,7 +19,7 @@ public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (product == null) diff --git a/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs index 31ad504..69995ad 100644 --- a/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs +++ b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs @@ -2,9 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Product; +namespace PyroFetes.Endpoints.Products; public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) : Endpoint @@ -17,7 +17,7 @@ public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) { - var product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct); + Product? product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct); if (product == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs index 856280f..ca26fde 100644 --- a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Product; +namespace PyroFetes.Endpoints.Products; public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint { @@ -14,7 +15,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Product? product = await database.Products.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (product == null) { diff --git a/PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs rename to PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs index a6a990a..a2d68a8 100644 --- a/PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs @@ -1,7 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseOrder; +namespace PyroFetes.Endpoints.PurchaseOrders; public class DeletePurchaseOrderRequest { @@ -18,7 +19,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct) { - var purchaseOrder = await database.PurchaseOrders + PurchaseOrder? purchaseOrder = await database.PurchaseOrders .Include(po => po.PurchaseProducts) .SingleOrDefaultAsync(po => po.Id == req.Id, ct); diff --git a/PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs similarity index 93% rename from PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs rename to PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs index c79de3d..b2e4c7e 100644 --- a/PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs @@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseProduct.Response; -namespace PyroFetes.Endpoints.PurchaseOrder; +namespace PyroFetes.Endpoints.PurchaseOrders; public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { @@ -14,7 +14,7 @@ public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(CancellationToken ct) { - var purchaseOrder = await database.PurchaseOrders + List purchaseOrder = await database.PurchaseOrders .Include(p => p.PurchaseProducts) .Select(purchaseOrder => new GetPurchaseOrderDto() { diff --git a/PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs similarity index 92% rename from PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs rename to PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs index 0f0562a..8920221 100644 --- a/PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseOrder; +namespace PyroFetes.Endpoints.PurchaseOrders; public class GetPurchaseOrderRequest { @@ -19,7 +20,7 @@ public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (purchaseOrder == null) diff --git a/PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs similarity index 90% rename from PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs rename to PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs index a6bbff0..04beca3 100644 --- a/PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs @@ -2,10 +2,10 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Response; -using PyroFetes.DTO.PurchaseProduct.Request; using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseOrder; +namespace PyroFetes.Endpoints.PurchaseOrders; public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint { @@ -17,7 +17,7 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext dat public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct) { - var purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct); + PurchaseOrder? purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct); if (purchaseOrder == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs similarity index 79% rename from PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs rename to PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs index f060c3a..3aad50d 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs @@ -1,9 +1,10 @@ -using Microsoft.EntityFrameworkCore; using FastEndpoints; +using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseProduct.Request; using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseProduct; +namespace PyroFetes.Endpoints.PurchaseProducts; public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,18 +16,18 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) { - var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); + Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); if (product == null) { await Send.NotFoundAsync(ct); return; } - var purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct); + PurchaseOrder? purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct); if (purchaseOrder == null) { - purchaseOrder = new Models.PurchaseOrder() + purchaseOrder = new PurchaseOrder() { PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" }; @@ -34,7 +35,7 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi await database.SaveChangesAsync(ct); } - var purchaseProduct = new Models.PurchaseProduct() + PurchaseProduct purchaseProduct = new PurchaseProduct() { ProductId = product.Id, PurchaseOrderId = purchaseOrder.Id, @@ -43,7 +44,7 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi database.PurchaseProducts.Add(purchaseProduct); await database.SaveChangesAsync(ct); - var responseDto = new GetPurchaseProductDto() + GetPurchaseProductDto responseDto = new GetPurchaseProductDto() { ProductId = product.Id, ProductReferences = product.Reference, diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs similarity index 87% rename from PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs rename to PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs index 93d60fb..3a06268 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs @@ -1,7 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseProduct; +namespace PyroFetes.Endpoints.PurchaseProducts; public class DeletePurchaseProductRequest { @@ -19,7 +20,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct) { - var purchaseProduct = await database.PurchaseProducts + PurchaseProduct? purchaseProduct = await database.PurchaseProducts .SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); if (purchaseProduct == null) diff --git a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs similarity index 81% rename from PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs rename to PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs index 952dd8d..1e72074 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs @@ -2,8 +2,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseProduct.Request; using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.PurchaseProduct; +namespace PyroFetes.Endpoints.PurchaseProducts; public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,7 +16,7 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct) { - var purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); + PurchaseProduct? purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); if (purchaseProduct == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs similarity index 80% rename from PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs rename to PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs index ada8499..6e24781 100644 --- a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs @@ -2,8 +2,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.QuotationProducts; public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,18 +16,18 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct) { - var product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); + Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); if (product == null) { await Send.NotFoundAsync(ct); return; } - var quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct); + Quotation? quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct); if (quotation == null) { - quotation = new Models.Quotation() + quotation = new Quotation() { Message = req.QuotationMessage ?? "", ConditionsSale = req.QuotationConditionsSale, @@ -35,7 +36,7 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo await database.SaveChangesAsync(ct); } - var quotationProduct = new Models.QuotationProduct() + QuotationProduct quotationProduct = new QuotationProduct() { ProductId = product.Id, QuotationId = quotation.Id, @@ -44,7 +45,7 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo database.QuotationProducts.Add(quotationProduct); await database.SaveChangesAsync(ct); - var responseDto = new GetQuotationProductDto() + GetQuotationProductDto responseDto = new GetQuotationProductDto() { ProductId = product.Id, ProductReferences = product.Reference, diff --git a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs similarity index 86% rename from PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs rename to PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs index aa480e8..2ee2d1e 100644 --- a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs @@ -1,7 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.QuotationProducts; public class DeleteQuotationProductRequest { @@ -19,7 +20,7 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct) { - var quotationProduct = await database.QuotationProducts + QuotationProduct? quotationProduct = await database.QuotationProducts .SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct); if (quotationProduct == null) diff --git a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs similarity index 81% rename from PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs rename to PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs index 33c050e..68034c9 100644 --- a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs @@ -2,8 +2,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.QuotationProducts; public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,7 +16,7 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct) { - var quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct); + QuotationProduct? quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct); if (quotationProduct == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs similarity index 89% rename from PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs rename to PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs index e83ae15..dbb0bfe 100644 --- a/PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs @@ -1,7 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Quotation; +namespace PyroFetes.Endpoints.Quotations; public class DeleteQuotationRequest { @@ -18,7 +19,7 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint q.QuotationProducts) .SingleOrDefaultAsync(q => q.Id == req.Id, ct); diff --git a/PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs similarity index 92% rename from PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs rename to PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs index 2dad3aa..f4efa10 100644 --- a/PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Quotation; +namespace PyroFetes.Endpoints.Quotations; public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { @@ -14,7 +15,7 @@ public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWith public override async Task HandleAsync(CancellationToken ct) { - var quotations = await database.Quotations + List quotations = await database.Quotations .Include(q => q.QuotationProducts!) .ThenInclude(qp => qp.Product) .Select(q => new GetQuotationDto diff --git a/PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs similarity index 93% rename from PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs rename to PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs index 162245c..0a455b4 100644 --- a/PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Quotation; +namespace PyroFetes.Endpoints.Quotations; public class GetQuotationRequest { @@ -19,7 +20,7 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (quotation == null) diff --git a/PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs rename to PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs index 8cc9609..1462f7e 100644 --- a/PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs @@ -1,13 +1,11 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseOrder.Request; -using PyroFetes.DTO.PurchaseOrder.Response; -using PyroFetes.DTO.PurchaseProduct.Response; using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Quotation; +namespace PyroFetes.Endpoints.Quotations; public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint { @@ -19,7 +17,7 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct) { - var quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + Quotation? quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (quotation == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs rename to PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs index 93250d6..97c35fb 100644 --- a/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs @@ -1,8 +1,9 @@ using FastEndpoints; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.SettingEndpoints; +namespace PyroFetes.Endpoints.Settings; public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint { @@ -13,7 +14,7 @@ public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (setting == null) { diff --git a/PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs rename to PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs index 34b059d..f3011ab 100644 --- a/PyroFetes/Endpoints/SettingEndpoints/GetSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs @@ -1,8 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.SettingEndpoints; +namespace PyroFetes.Endpoints.Settings; public class GetSettingRequest { @@ -18,7 +19,7 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (setting == null) diff --git a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs similarity index 86% rename from PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs rename to PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs index 39e8459..7119c1d 100644 --- a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.SettingEndpoints; +namespace PyroFetes.Endpoints.Settings; public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint { @@ -14,7 +15,7 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) { - var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (setting == null) { diff --git a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs similarity index 84% rename from PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs rename to PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs index 553800a..8916f20 100644 --- a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.SettingEndpoints; +namespace PyroFetes.Endpoints.Settings; public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint { @@ -14,7 +15,7 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (setting == null) { diff --git a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs similarity index 86% rename from PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs index 6232481..0bf6b9e 100644 --- a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs @@ -1,8 +1,9 @@ -using PyroFetes.DTO.Supplier.Request; +using FastEndpoints; +using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; -using FastEndpoints; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint { @@ -13,7 +14,7 @@ public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (supplier == null) { diff --git a/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs b/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs similarity index 86% rename from PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs index b550c85..ea65f22 100644 --- a/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs @@ -1,9 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseProduct.Response; using PyroFetes.DTO.Supplier.Response; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { @@ -14,7 +13,7 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWith public override async Task HandleAsync(CancellationToken ct) { - var supplier = await database.Suppliers + List supplier = await database.Suppliers .Select(supplier => new GetSupplierDto() { Id = supplier.Id, diff --git a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs similarity index 90% rename from PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs index 40b6e8e..a2dec7c 100644 --- a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs @@ -1,8 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class GetSupplierRequest { @@ -18,7 +19,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (supplier == null) diff --git a/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs similarity index 84% rename from PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs index ea31903..3574f2e 100644 --- a/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint { @@ -14,7 +15,7 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) { - var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (supplier == null) { diff --git a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs index ab68ebb..6a81bbc 100644 --- a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs @@ -2,8 +2,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint { @@ -14,7 +15,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (supplier == null) { diff --git a/PyroFetes/Endpoints/User/ConnectUserEndpoint.cs b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs similarity index 86% rename from PyroFetes/Endpoints/User/ConnectUserEndpoint.cs rename to PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs index b84c932..7ddff69 100644 --- a/PyroFetes/Endpoints/User/ConnectUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs @@ -3,8 +3,9 @@ using FastEndpoints.Security; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint { @@ -16,7 +17,7 @@ public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint x.Name == req.Name, ct); + User? user = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct); if (user == null) { @@ -26,7 +27,7 @@ public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint { o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong"; diff --git a/PyroFetes/Endpoints/User/CreateUserEndpoint.cs b/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs similarity index 92% rename from PyroFetes/Endpoints/User/CreateUserEndpoint.cs rename to PyroFetes/Endpoints/Users/CreateUserEndpoint.cs index 466cb8b..a923b4e 100644 --- a/PyroFetes/Endpoints/User/CreateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs @@ -2,8 +2,9 @@ using PasswordGenerator; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint { @@ -17,7 +18,7 @@ public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (user == null) { diff --git a/PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs b/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs similarity index 88% rename from PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs rename to PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs index 5b027b5..65506a8 100644 --- a/PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs +++ b/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Response; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> { @@ -13,7 +13,7 @@ public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutR public override async Task HandleAsync(CancellationToken ct) { - var users = await database.Users + List users = await database.Users .Select(users => new GetUserDto() { Id = users.Id, diff --git a/PyroFetes/Endpoints/User/GetUserEndpoint.cs b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs similarity index 90% rename from PyroFetes/Endpoints/User/GetUserEndpoint.cs rename to PyroFetes/Endpoints/Users/GetUserEndpoint.cs index f373674..0de2798 100644 --- a/PyroFetes/Endpoints/User/GetUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs @@ -1,8 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class GetUserRequest { @@ -18,7 +19,7 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); if (user == null) diff --git a/PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs similarity index 87% rename from PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs rename to PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs index 4049b89..17e5af8 100644 --- a/PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs +++ b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs @@ -2,8 +2,9 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,7 +16,7 @@ public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint

x.Id == req.Id, ct); + User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); if (user == null) { await Send.NotFoundAsync(ct); diff --git a/PyroFetes/Endpoints/User/UpdateUserEndpoint.cs b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs similarity index 85% rename from PyroFetes/Endpoints/User/UpdateUserEndpoint.cs rename to PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs index 13a8935..0ecc3c1 100644 --- a/PyroFetes/Endpoints/User/UpdateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs @@ -3,8 +3,9 @@ using Microsoft.EntityFrameworkCore; using PasswordGenerator; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint { @@ -15,8 +16,8 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); - var ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct); + User? user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + User? ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct); if (user == null) { diff --git a/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs similarity index 84% rename from PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs rename to PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs index 0005391..a6398c8 100644 --- a/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs @@ -1,8 +1,9 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.WareHouseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.WareHouseProduct; +namespace PyroFetes.Endpoints.WareHouseProducts; public class GetTotalQuantityRequest { @@ -19,7 +20,7 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint wp.ProductId == req.ProductId, ct); if (!exists) @@ -28,7 +29,7 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint wp.ProductId == req.ProductId) .SumAsync(wp => wp.Quantity, ct); diff --git a/PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProducts/PatchWareHouseProductQuantityEndpoint.cs similarity index 78% rename from PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs rename to PyroFetes/Endpoints/WareHouseProducts/PatchWareHouseProductQuantityEndpoint.cs index d5cc5f8..5426645 100644 --- a/PyroFetes/Endpoints/WareHouseProduct/PatchWareHouseProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/WareHouseProducts/PatchWareHouseProductQuantityEndpoint.cs @@ -1,11 +1,10 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.QuotationProduct.Request; -using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.DTO.WareHouseProduct.Request; using PyroFetes.DTO.WareHouseProduct.Response; +using PyroFetes.Models; -namespace PyroFetes.Endpoints.WareHouseProduct; +namespace PyroFetes.Endpoints.WareHouseProducts; public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint { @@ -17,7 +16,7 @@ public class PatchWareHouseProductQuantityEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(PatchWareHouseProductQuantityDto req, CancellationToken ct) { - var wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct); + WarehouseProduct? wareHouseProduct = await database.WarehouseProducts.SingleOrDefaultAsync(wp => wp.ProductId == req.ProductId && wp.WarehouseId == req.WareHouseId, ct); if (wareHouseProduct == null) { await Send.NotFoundAsync(ct); From 0511bb507533c8468293ed8ac3568a2d77d2754d Mon Sep 17 00:00:00 2001 From: sanchezvem Date: Mon, 17 Nov 2025 21:25:07 +0100 Subject: [PATCH 06/16] added AllowAnonymous(); --- .../Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs | 1 + PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs | 1 + PyroFetes/Endpoints/Products/GetProductEndpoint.cs | 1 + PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs | 1 + .../Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs | 1 + PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs | 1 + PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs | 1 + PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs | 1 + PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs | 1 + PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs | 1 + PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs | 1 + .../Settings/PatchSettingElectronicSignatureEndpoint.cs | 3 ++- PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs | 3 ++- PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs | 1 + PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs | 1 + PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs | 1 + PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs | 1 + .../Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs | 3 ++- PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs | 1 + PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs | 1 + PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs | 1 + PyroFetes/Endpoints/Users/GetUserEndpoint.cs | 1 + PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs | 1 + 23 files changed, 26 insertions(+), 3 deletions(-) diff --git a/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs index bc7a44a..1e2c0f3 100644 --- a/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs +++ b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs @@ -18,6 +18,7 @@ public class CreateDeliveryNoteEndpoint( public override void Configure() { Post("/api/DeliveryNote"); + AllowAnonymous(); } public override async Task HandleAsync(CreateDeliveryNoteDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs index e0d13d8..a61104f 100644 --- a/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs +++ b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs @@ -10,6 +10,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWitho public override void Configure() { Get("/api/products"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs index 2125a9c..d1c39f8 100644 --- a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs @@ -15,6 +15,7 @@ public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetProductRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs index ca26fde..8dc8172 100644 --- a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs @@ -11,6 +11,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs index b2e4c7e..69c1fb1 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs @@ -10,6 +10,7 @@ public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override void Configure() { Get("/api/purchaseOrders"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs index 8920221..374ec4c 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs @@ -16,6 +16,7 @@ public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs index f4efa10..44f3f5b 100644 --- a/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/GetAllQuotationEndpoint.cs @@ -11,6 +11,7 @@ public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWith public override void Configure() { Get("/api/quotations"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs index 0a455b4..d600e0f 100644 --- a/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs @@ -16,6 +16,7 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs index 97c35fb..1fd6ec9 100644 --- a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs @@ -10,6 +10,7 @@ public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(DeleteSettingRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs index f3011ab..b0656f6 100644 --- a/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/GetSettingEndpoint.cs @@ -15,6 +15,7 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetSettingRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs index 7119c1d..b62776c 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs @@ -10,7 +10,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database { public override void Configure() { - Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); + Patch("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs index 8916f20..ef974c7 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs @@ -10,7 +10,8 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + Patch("/api/setting/{@Id}/Logo", x => new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs index 0bf6b9e..8ec116f 100644 --- a/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs @@ -10,6 +10,7 @@ public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs b/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs index ea65f22..8e13b2e 100644 --- a/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/GetAllSuppliersEndpoint.cs @@ -9,6 +9,7 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWith public override void Configure() { Get("/api/suppliers"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs index a2dec7c..628969d 100644 --- a/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs @@ -15,6 +15,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs index 3574f2e..85d4040 100644 --- a/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs @@ -10,7 +10,8 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E { public override void Configure() { - Get("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); + Patch("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs index 6a81bbc..e9c4ef4 100644 --- a/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs @@ -11,6 +11,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs index e69acdf..d5b0b62 100644 --- a/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs @@ -14,6 +14,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(DeleteUserRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs b/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs index 65506a8..ddcd588 100644 --- a/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs +++ b/PyroFetes/Endpoints/Users/GetAllUsersEndpoint.cs @@ -9,6 +9,7 @@ public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutR public override void Configure() { Get("/api/users"); + AllowAnonymous(); } public override async Task HandleAsync(CancellationToken ct) diff --git a/PyroFetes/Endpoints/Users/GetUserEndpoint.cs b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs index 0de2798..3bcc589 100644 --- a/PyroFetes/Endpoints/Users/GetUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs @@ -15,6 +15,7 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) diff --git a/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs index 0ecc3c1..20bb3d4 100644 --- a/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs @@ -12,6 +12,7 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint new {x.Id}); + AllowAnonymous(); } public override async Task HandleAsync(UpdateUserDto req, CancellationToken ct) From bd653c149c25a57becbd6c69b82d16a95a58b476 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Wed, 19 Nov 2025 18:05:28 +0100 Subject: [PATCH 07/16] Finished refactoring prices endpoints --- .../Endpoints/Prices/DeletePriceEndpoint.cs | 12 +++++----- .../Endpoints/Prices/PatchPriceEndpoint.cs | 23 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs index deb47e0..513e8d9 100644 --- a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Prices; namespace PyroFetes.Endpoints.Prices; @@ -10,7 +12,7 @@ public class DeletePriceRequest public int SupplierId { get; set; } } -public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint { public override void Configure() { @@ -20,8 +22,7 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId,req.SupplierId), ct); if (price == null) { @@ -29,9 +30,8 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchPriceEndpoint( + PricesRepository pricesRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +19,8 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); + Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct); + if (price == null) { await Send.NotFoundAsync(ct); @@ -24,14 +28,9 @@ public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint(price), ct); } } \ No newline at end of file From 7bf0b5bfd14caefc468b165957740227649a6be0 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 14:04:13 +0100 Subject: [PATCH 08/16] Advanced refactoring --- .../Endpoints/Prices/DeletePriceEndpoint.cs | 2 +- .../Products/GetAllProductsEndpoint.cs | 22 ++-------- .../Endpoints/Products/GetProductEndpoint.cs | 26 ++++-------- .../PatchProductMinimalStockEndpoint.cs | 30 +++++--------- .../Products/UpdateProductEndpoint.cs | 26 ++++-------- .../DeletePurchaseOrderEndpoint.cs | 15 +++---- .../GetAllPurchaseOrderEndpoint.cs | 31 ++------------ .../GetPurchaseOrderEndpoint.cs | 34 ++++----------- ...PurchaseOrderPurchaseConditionsEndpoint.cs | 34 ++++----------- .../CreatePurchaseProductEndpoint.cs | 41 +++++++------------ .../DeletePurchaseProductEndpoint.cs | 11 ++--- .../PatchPurchaseProductQuantityEndpoint.cs | 21 +++++----- .../Repositories/PurchaseOrdersRepository.cs | 5 +++ .../PurchaseProductsRepository.cs | 5 +++ .../GetPurchaseOrderByIdSpec.cs | 14 +++++++ ...roductByProductIdAndPurchaseOrderIdSpec.cs | 13 ++++++ 16 files changed, 123 insertions(+), 207 deletions(-) create mode 100644 PyroFetes/Repositories/PurchaseOrdersRepository.cs create mode 100644 PyroFetes/Repositories/PurchaseProductsRepository.cs create mode 100644 PyroFetes/Specifications/PurchaseOrders/GetPurchaseOrderByIdSpec.cs create mode 100644 PyroFetes/Specifications/PurchaseProducts/GetPurchaseProductByProductIdAndPurchaseOrderIdSpec.cs diff --git a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs index 513e8d9..260c7cb 100644 --- a/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs @@ -32,6 +32,6 @@ public class DeletePriceEndpoint(PricesRepository pricesRepository) : Endpoint> +public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest> { public override void Configure() { @@ -15,23 +16,6 @@ public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWitho public override async Task HandleAsync(CancellationToken ct) { - List product = await database.Products - .Select(product => new GetProductDto() - { - Id = product.Id, - References = product.Reference, - Name = product.Name, - Duration = product.Duration, - Caliber = product.Caliber, - ApprovalNumber = product.ApprovalNumber, - Weight = product.Weight, - Nec = product.Nec, - Image = product.Image, - Link = product.Link, - MinimalQuantity = product.MinimalQuantity, - }) - .ToListAsync(ct); - - await Send.OkAsync(product, ct); + await Send.OkAsync(await productsRepository.ProjectToListAsync(ct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs index d1c39f8..7e458a3 100644 --- a/PyroFetes/Endpoints/Products/GetProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; namespace PyroFetes.Endpoints.Products; @@ -10,7 +12,9 @@ public class GetProductRequest public int Id { get; set; } } -public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint +public class GetProductEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -20,8 +24,7 @@ public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); if (product == null) { @@ -29,21 +32,6 @@ public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint(product), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs index 69995ad..51bfd1d 100644 --- a/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs +++ b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs @@ -3,11 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; namespace PyroFetes.Endpoints.Products; -public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) - : Endpoint +public class PatchProductMinimalStockEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -17,7 +20,8 @@ public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) { - Product? product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); + if (product == null) { await Send.NotFoundAsync(ct); @@ -25,22 +29,8 @@ public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) } product.MinimalQuantity = req.MinimalQuantity; - await database.SaveChangesAsync(ct); - - GetProductDto responseDto = new() - { - Id = product.Id, - References = product.Reference, - Name = product.Name, - Duration = product.Duration, - Caliber = product.Caliber, - ApprovalNumber = product.ApprovalNumber, - Weight = product.Weight, - Nec = product.Nec, - Image = product.Image, - Link = product.Link, - MinimalQuantity = product.MinimalQuantity, - }; - await Send.OkAsync(responseDto, ct); + await productsRepository.UpdateAsync(product, ct); + + await Send.OkAsync(mapper.Map(product), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs index 8dc8172..83df9ac 100644 --- a/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Product.Request; using PyroFetes.DTO.Product.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; namespace PyroFetes.Endpoints.Products; -public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateProductEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); if (product == null) { @@ -34,23 +38,9 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint(product), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs index a2d68a8..23098d8 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders; @@ -9,7 +11,9 @@ public class DeletePurchaseOrderRequest public int Id { get; set; } } -public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint +public class DeletePurchaseOrderEndpoint( + PurchaseOrdersRepository purchaseOrdersRepository, + PurchaseProductsRepository purchaseProductsRepository) : Endpoint { public override void Configure() { @@ -19,9 +23,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct) { - PurchaseOrder? purchaseOrder = await database.PurchaseOrders - .Include(po => po.PurchaseProducts) - .SingleOrDefaultAsync(po => po.Id == req.Id, ct); + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); if (purchaseOrder == null) { @@ -31,11 +33,10 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint if (purchaseOrder.PurchaseProducts != null && purchaseOrder.PurchaseProducts.Any()) { - database.PurchaseProducts.RemoveRange(purchaseOrder.PurchaseProducts); + await purchaseProductsRepository.DeleteRangeAsync(purchaseOrder.PurchaseProducts, ct); } - database.PurchaseOrders.Remove(purchaseOrder); - await database.SaveChangesAsync(ct); + await purchaseOrdersRepository.DeleteAsync(purchaseOrder, ct); await Send.NoContentAsync(ct); } diff --git a/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs index 69c1fb1..f60fc95 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs @@ -2,10 +2,11 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Repositories; namespace PyroFetes.Endpoints.PurchaseOrders; -public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> +public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : EndpointWithoutRequest> { public override void Configure() { @@ -15,32 +16,6 @@ public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(CancellationToken ct) { - List purchaseOrder = await database.PurchaseOrders - .Include(p => p.PurchaseProducts) - .Select(purchaseOrder => new GetPurchaseOrderDto() - { - Id = purchaseOrder.Id, - PurchaseConditions = purchaseOrder.PurchaseConditions, - GetPurchaseProductDto = purchaseOrder.PurchaseProducts - .Select(p => new GetPurchaseProductDto - { - ProductId = p.ProductId, - ProductReferences = p.Product.Reference, - ProductName = p.Product.Name, - ProductDuration = p.Product.Duration, - ProductCaliber = p.Product.Caliber, - ProductApprovalNumber = p.Product.ApprovalNumber, - ProductWeight = p.Product.Weight, - ProductNec = p.Product.Nec, - ProductImage = p.Product.Image, - ProductLink = p.Product.Link, - ProductMinimalQuantity = p.Product.MinimalQuantity, - PurchaseOrderId = p.PurchaseOrderId, - Quantity = p.Quantity, - }).ToList() - }) - .ToListAsync(ct); - - await Send.OkAsync(purchaseOrder, ct); + await Send.OkAsync(await purchaseOrdersRepository.ProjectToListAsync(ct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs index 374ec4c..16823ed 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders; @@ -11,7 +13,9 @@ public class GetPurchaseOrderRequest public int Id { get; set; } } -public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint +public class GetPurchaseOrderEndpoint( + PurchaseOrdersRepository purchaseOrdersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -21,8 +25,7 @@ public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); if (purchaseOrder == null) { @@ -30,29 +33,6 @@ public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint new GetPurchaseProductDto - { - ProductId = p.ProductId, - ProductReferences = p.Product.Reference, - ProductName = p.Product.Name, - ProductDuration = p.Product.Duration, - ProductCaliber = p.Product.Caliber, - ProductApprovalNumber = p.Product.ApprovalNumber, - ProductWeight = p.Product.Weight, - ProductNec = p.Product.Nec, - ProductImage = p.Product.Image, - ProductLink = p.Product.Link, - ProductMinimalQuantity = p.Product.MinimalQuantity, - PurchaseOrderId = p.PurchaseOrderId, - Quantity = p.Quantity, - }).ToList() - }; - - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(purchaseOrder), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs index 04beca3..c422f4a 100644 --- a/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs @@ -4,10 +4,14 @@ using PyroFetes.DTO.PurchaseOrder.Request; using PyroFetes.DTO.PurchaseOrder.Response; using PyroFetes.DTO.PurchaseProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; namespace PyroFetes.Endpoints.PurchaseOrders; -public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchPurchaseOrderPurchaseConditionsEndpoint( + PurchaseOrdersRepository purchaseOrdersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -17,7 +21,7 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext dat public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct) { - PurchaseOrder? purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct); + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); if (purchaseOrder == null) { await Send.NotFoundAsync(ct); @@ -25,30 +29,8 @@ public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext dat } purchaseOrder.PurchaseConditions = req.PurchaseConditions; - await database.SaveChangesAsync(ct); + await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct); - GetPurchaseOrderDto responseDto = new() - { - Id = purchaseOrder.Id, - PurchaseConditions = purchaseOrder.PurchaseConditions, - GetPurchaseProductDto = purchaseOrder.PurchaseProducts - .Select(p => new GetPurchaseProductDto - { - ProductId = p.ProductId, - ProductReferences = p.Product.Reference, - ProductName = p.Product.Name, - ProductDuration = p.Product.Duration, - ProductCaliber = p.Product.Caliber, - ProductApprovalNumber = p.Product.ApprovalNumber, - ProductWeight = p.Product.Weight, - ProductNec = p.Product.Nec, - ProductImage = p.Product.Image, - ProductLink = p.Product.Link, - ProductMinimalQuantity = p.Product.MinimalQuantity, - PurchaseOrderId = p.PurchaseOrderId, - Quantity = p.Quantity, - }).ToList() - }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(purchaseOrder), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs index 3aad50d..464f1f2 100644 --- a/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs @@ -3,10 +3,17 @@ 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(PyroFetesDbContext database) : Endpoint +public class CreatePurchaseProductEndpoint( + ProductsRepository productsRepository, + PurchaseOrdersRepository purchaseOrdersRepository, + PurchaseProductsRepository purchaseProductsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,14 +23,14 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) { - Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); if (product == null) { await Send.NotFoundAsync(ct); return; } - PurchaseOrder? purchaseOrder = await database.PurchaseOrders.FirstOrDefaultAsync(po => po.Id == req.PurchaseOrderId, ct); + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct); if (purchaseOrder == null) { @@ -31,8 +38,7 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi { PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" }; - database.PurchaseOrders.Add(purchaseOrder); - await database.SaveChangesAsync(ct); + await purchaseOrdersRepository.AddAsync(purchaseOrder, ct); } PurchaseProduct purchaseProduct = new PurchaseProduct() @@ -41,28 +47,9 @@ public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoi PurchaseOrderId = purchaseOrder.Id, Quantity = req.Quantity }; - database.PurchaseProducts.Add(purchaseProduct); - await database.SaveChangesAsync(ct); - GetPurchaseProductDto responseDto = new GetPurchaseProductDto() - { - ProductId = product.Id, - ProductReferences = product.Reference, - ProductName = product.Name, - ProductDuration = product.Duration, - ProductCaliber = product.Caliber, - ProductApprovalNumber = product.ApprovalNumber, - ProductWeight = product.Weight, - ProductNec = product.Nec, - ProductImage = product.Image, - ProductLink = product.Link, - ProductMinimalQuantity = product.MinimalQuantity, - - PurchaseOrderId = purchaseOrder.Id, - PurchaseOrderPurchaseConditions = purchaseOrder.PurchaseConditions, - Quantity = purchaseProduct.Quantity - }; - - await Send.OkAsync(responseDto, ct); + await purchaseProductsRepository.AddAsync(purchaseProduct, ct); + + await Send.OkAsync(mapper.Map(purchaseProduct), ct); } } diff --git a/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs index 3a06268..811cade 100644 --- a/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseProducts; namespace PyroFetes.Endpoints.PurchaseProducts; @@ -10,7 +12,7 @@ public class DeletePurchaseProductRequest public int PurchaseOrderId { get; set; } } -public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint +public class DeletePurchaseProductEndpoint(PurchaseProductsRepository purchaseProductsRepository) : Endpoint { public override void Configure() { @@ -20,8 +22,8 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct) { - PurchaseProduct? purchaseProduct = await database.PurchaseProducts - .SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); + PurchaseProduct? purchaseProduct = await purchaseProductsRepository.FirstOrDefaultAsync( + new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct); if (purchaseProduct == null) { @@ -29,8 +31,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint return; } - database.PurchaseProducts.Remove(purchaseProduct); - await database.SaveChangesAsync(ct); + await purchaseProductsRepository.DeleteAsync(purchaseProduct, ct); await Send.NoContentAsync(ct); } diff --git a/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs index 1e72074..17a88c4 100644 --- a/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs @@ -3,10 +3,14 @@ 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(PyroFetesDbContext database) : Endpoint +public class PatchPurchaseProductQuantityEndpoint( + PurchaseProductsRepository purchaseProductsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,10 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct) { - PurchaseProduct? purchaseProduct = await database.PurchaseProducts.SingleOrDefaultAsync(po => po.ProductId == req.ProductId && po.PurchaseOrderId == req.PurchaseOrderId, ct); + PurchaseProduct? purchaseProduct = + await purchaseProductsRepository.FirstOrDefaultAsync( + new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct); + if (purchaseProduct == null) { await Send.NotFoundAsync(ct); @@ -24,14 +31,8 @@ public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : } purchaseProduct.Quantity = req.Quantity; - await database.SaveChangesAsync(ct); + await purchaseProductsRepository.UpdateAsync(purchaseProduct, ct); - GetPurchaseProductDto responseDto = new() - { - ProductId = purchaseProduct.ProductId, - PurchaseOrderId = purchaseProduct.PurchaseOrderId, - Quantity = purchaseProduct.Quantity - }; - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(purchaseProduct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Repositories/PurchaseOrdersRepository.cs b/PyroFetes/Repositories/PurchaseOrdersRepository.cs new file mode 100644 index 0000000..d5ce765 --- /dev/null +++ b/PyroFetes/Repositories/PurchaseOrdersRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class PurchaseOrdersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Repositories/PurchaseProductsRepository.cs b/PyroFetes/Repositories/PurchaseProductsRepository.cs new file mode 100644 index 0000000..b5de25b --- /dev/null +++ b/PyroFetes/Repositories/PurchaseProductsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class PurchaseProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/PurchaseOrders/GetPurchaseOrderByIdSpec.cs b/PyroFetes/Specifications/PurchaseOrders/GetPurchaseOrderByIdSpec.cs new file mode 100644 index 0000000..272ad75 --- /dev/null +++ b/PyroFetes/Specifications/PurchaseOrders/GetPurchaseOrderByIdSpec.cs @@ -0,0 +1,14 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.PurchaseOrders; + +public sealed class GetPurchaseOrderByIdSpec : Specification +{ + public GetPurchaseOrderByIdSpec(int purchaseOrderId) + { + Query + .Include(po => po.PurchaseProducts) + .Where(po => po.Id == purchaseOrderId); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/PurchaseProducts/GetPurchaseProductByProductIdAndPurchaseOrderIdSpec.cs b/PyroFetes/Specifications/PurchaseProducts/GetPurchaseProductByProductIdAndPurchaseOrderIdSpec.cs new file mode 100644 index 0000000..5d35c62 --- /dev/null +++ b/PyroFetes/Specifications/PurchaseProducts/GetPurchaseProductByProductIdAndPurchaseOrderIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.PurchaseProducts; + +public sealed class GetPurchaseProductByProductIdAndPurchaseOrderIdSpec : Specification +{ + public GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(int productId, int purchaseOrderId) + { + Query + .Where(p => p.ProductId == productId && p.PurchaseOrderId == purchaseOrderId); + } +} \ No newline at end of file From f6383265badabc894316fab73bb7248feef3324b Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 14:20:25 +0100 Subject: [PATCH 09/16] Refactored QuotationProduct --- .../CreateQuotationProductEndpoint.cs | 41 +++++++------------ .../DeleteQuotationProductEndpoint.cs | 12 +++--- .../PatchQuotationProductQuantityEndpoint.cs | 22 +++++----- .../QuotationProductsRepository.cs | 5 +++ .../Repositories/QuotationsRepository.cs | 5 +++ ...ionProductByProductIdAndQuotationIdSpec.cs | 13 ++++++ .../Quotations/GetQuotationByIdSpec.cs | 13 ++++++ 7 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 PyroFetes/Repositories/QuotationProductsRepository.cs create mode 100644 PyroFetes/Repositories/QuotationsRepository.cs create mode 100644 PyroFetes/Specifications/QuotationProducts/GetQuotationProductByProductIdAndQuotationIdSpec.cs create mode 100644 PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs diff --git a/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs index 6e24781..0c64357 100644 --- a/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs @@ -3,10 +3,17 @@ 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(PyroFetesDbContext database) : Endpoint +public class CreateQuotationProductEndpoint( + QuotationProductsRepository quotationProductsRepository, + ProductsRepository productsRepository, + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,14 +23,15 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct) { - Product? product = await database.Products.FirstOrDefaultAsync(p => p.Id == req.ProductId, ct); + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + if (product == null) { await Send.NotFoundAsync(ct); return; } - Quotation? quotation = await database.Quotations.FirstOrDefaultAsync(q => q.Id == req.QuotationId, ct); + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct); if (quotation == null) { @@ -32,8 +40,8 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo Message = req.QuotationMessage ?? "", ConditionsSale = req.QuotationConditionsSale, }; - database.Quotations.Add(quotation); - await database.SaveChangesAsync(ct); + + await quotationsRepository.AddAsync(quotation, ct); } QuotationProduct quotationProduct = new QuotationProduct() @@ -42,28 +50,9 @@ public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpo QuotationId = quotation.Id, Quantity = req.Quantity }; - database.QuotationProducts.Add(quotationProduct); - await database.SaveChangesAsync(ct); - GetQuotationProductDto responseDto = new GetQuotationProductDto() - { - ProductId = product.Id, - ProductReferences = product.Reference, - ProductName = product.Name, - ProductDuration = product.Duration, - ProductCaliber = product.Caliber, - ProductApprovalNumber = product.ApprovalNumber, - ProductWeight = product.Weight, - ProductNec = product.Nec, - ProductImage = product.Image, - ProductLink = product.Link, - ProductMinimalQuantity = product.MinimalQuantity, - Quantity = quotationProduct.Quantity, - QuotationMessage = quotation.Message, - QuotationConditionsSale = quotation.ConditionsSale, - QuotationId = quotation.Id, - }; + await quotationProductsRepository.AddAsync(quotationProduct, ct); - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(quotationProduct), ct); } } diff --git a/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs index 2ee2d1e..c680325 100644 --- a/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.QuotationProducts; namespace PyroFetes.Endpoints.QuotationProducts; @@ -10,7 +12,7 @@ public class DeleteQuotationProductRequest public int QuotationId { get; set; } } -public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteQuotationProductEndpoint(QuotationProductsRepository quotationProductsRepository) : Endpoint { public override void Configure() { @@ -20,8 +22,9 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct) { - QuotationProduct? quotationProduct = await database.QuotationProducts - .SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct); + QuotationProduct? quotationProduct = + await quotationProductsRepository.FirstOrDefaultAsync( + new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct); if (quotationProduct == null) { @@ -29,8 +32,7 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo return; } - database.QuotationProducts.Remove(quotationProduct); - await database.SaveChangesAsync(ct); + await quotationProductsRepository.DeleteAsync(quotationProduct, ct); await Send.NoContentAsync(ct); } diff --git a/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs index 68034c9..26f3691 100644 --- a/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.QuotationProduct.Request; using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.QuotationProducts; namespace PyroFetes.Endpoints.QuotationProducts; -public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchQuotationProductQuantityEndpoint( + QuotationProductsRepository quotationProductsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,9 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct) { - QuotationProduct? quotationProduct = await database.QuotationProducts.SingleOrDefaultAsync(qo => qo.ProductId == req.ProductId && qo.QuotationId == req.QuotationId, ct); + QuotationProduct? quotationProduct = + await quotationProductsRepository.FirstOrDefaultAsync( + new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct); if (quotationProduct == null) { await Send.NotFoundAsync(ct); @@ -24,14 +30,8 @@ public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) } quotationProduct.Quantity = req.Quantity; - await database.SaveChangesAsync(ct); - - GetQuotationProductDto responseDto = new() - { - ProductId = quotationProduct.ProductId, - QuotationId = quotationProduct.QuotationId, - Quantity = quotationProduct.Quantity - }; - await Send.OkAsync(responseDto, ct); + await quotationProductsRepository.UpdateAsync(quotationProduct, ct); + + await Send.OkAsync(mapper.Map(quotationProduct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Repositories/QuotationProductsRepository.cs b/PyroFetes/Repositories/QuotationProductsRepository.cs new file mode 100644 index 0000000..0d42cdc --- /dev/null +++ b/PyroFetes/Repositories/QuotationProductsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class QuotationProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); diff --git a/PyroFetes/Repositories/QuotationsRepository.cs b/PyroFetes/Repositories/QuotationsRepository.cs new file mode 100644 index 0000000..1b99ed9 --- /dev/null +++ b/PyroFetes/Repositories/QuotationsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class QuotationsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/QuotationProducts/GetQuotationProductByProductIdAndQuotationIdSpec.cs b/PyroFetes/Specifications/QuotationProducts/GetQuotationProductByProductIdAndQuotationIdSpec.cs new file mode 100644 index 0000000..9c3b65a --- /dev/null +++ b/PyroFetes/Specifications/QuotationProducts/GetQuotationProductByProductIdAndQuotationIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.QuotationProducts; + +public sealed class GetQuotationProductByProductIdAndQuotationIdSpec : Specification +{ + public GetQuotationProductByProductIdAndQuotationIdSpec(int productId, int quotationId) + { + Query + .Where(x => x.ProductId == productId && x.QuotationId == quotationId); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs b/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs new file mode 100644 index 0000000..89ff725 --- /dev/null +++ b/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Quotations; + +public sealed class GetQuotationByIdSpec : Specification +{ + public GetQuotationByIdSpec(int quotationId) + { + Query + .Where(x => x.Id == quotationId); + } +} \ No newline at end of file From ee9b4675dd17792d7f570361d4226d3d71a6cd98 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 14:34:09 +0100 Subject: [PATCH 10/16] Refactored Quotation --- .../Quotations/DeleteQuotationEndpoint.cs | 15 ++++---- .../Quotations/GetAllQuotationEndpoint.cs | 34 ++--------------- .../Quotations/GetQuotationEndpoint.cs | 37 ++++-------------- .../PatchQuotationConditionsSaleEndpoint.cs | 38 +++++-------------- .../Quotations/GetQuotationByIdSpec.cs | 1 + 5 files changed, 29 insertions(+), 96 deletions(-) diff --git a/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs index dbb0bfe..06ef33c 100644 --- a/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; namespace PyroFetes.Endpoints.Quotations; @@ -9,7 +11,9 @@ public class DeleteQuotationRequest public int Id { get; set; } } -public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteQuotationEndpoint( + QuotationsRepository quotationsRepository, + QuotationProductsRepository quotationProductsRepository) : Endpoint { public override void Configure() { @@ -19,9 +23,7 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint q.QuotationProducts) - .SingleOrDefaultAsync(q => q.Id == req.Id, ct); + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); if (quotation == null) { @@ -31,11 +33,10 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint> +public class GetAllQuotationEndpoint(QuotationsRepository quotationsRepository) : EndpointWithoutRequest> { public override void Configure() { @@ -16,35 +17,6 @@ public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWith public override async Task HandleAsync(CancellationToken ct) { - List quotations = await database.Quotations - .Include(q => q.QuotationProducts!) - .ThenInclude(qp => qp.Product) - .Select(q => new GetQuotationDto - { - Id = q.Id, - Message = q.Message, - ConditionsSale = q.ConditionsSale, - GetQuotationProductDto = q.QuotationProducts.Select(qp => new GetQuotationProductDto - { - Quantity = qp.Quantity, - QuotationId = q.Id, - QuotationMessage = q.Message, - QuotationConditionsSale = q.ConditionsSale, - ProductId = qp.ProductId, - ProductReferences = qp.Product.Reference, - ProductName = qp.Product.Name, - ProductDuration = qp.Product.Duration, - ProductCaliber = qp.Product.Caliber, - ProductApprovalNumber = qp.Product.ApprovalNumber, - ProductWeight = qp.Product.Weight, - ProductNec = qp.Product.Nec, - ProductImage = qp.Product.Image, - ProductLink = qp.Product.Link, - ProductMinimalQuantity = qp.Product.MinimalQuantity, - }).ToList() - }) - .ToListAsync(ct); - - await Send.OkAsync(quotations, ct); + await Send.OkAsync(await quotationsRepository.ProjectToListAsync(ct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs index d600e0f..6c2355b 100644 --- a/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; namespace PyroFetes.Endpoints.Quotations; @@ -11,7 +13,9 @@ public class GetQuotationRequest public int Id { get; set; } } -public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint +public class GetQuotationEndpoint( + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -21,8 +25,7 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); if (quotation == null) { @@ -30,32 +33,6 @@ public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint new GetQuotationProductDto - { - Quantity = qp.Quantity, - QuotationId = quotation.Id, - QuotationMessage = quotation.Message, - QuotationConditionsSale = quotation.ConditionsSale, - ProductId = qp.ProductId, - ProductReferences = qp.Product.Reference, - ProductName = qp.Product.Name, - ProductDuration = qp.Product.Duration, - ProductCaliber = qp.Product.Caliber, - ProductApprovalNumber = qp.Product.ApprovalNumber, - ProductWeight = qp.Product.Weight, - ProductNec = qp.Product.Nec, - ProductImage = qp.Product.Image, - ProductLink = qp.Product.Link, - ProductMinimalQuantity = qp.Product.MinimalQuantity, - }).ToList() - }; - - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(quotation), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs index 1462f7e..c68d1e9 100644 --- a/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs @@ -4,10 +4,14 @@ using PyroFetes.DTO.Quotation.Request; using PyroFetes.DTO.Quotation.Response; using PyroFetes.DTO.QuotationProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; namespace PyroFetes.Endpoints.Quotations; -public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchQuotationConditionsSaleEndpoint( + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -17,7 +21,8 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct) { - Quotation? quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); + if (quotation == null) { await Send.NotFoundAsync(ct); @@ -25,32 +30,9 @@ public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : } quotation.ConditionsSale = req.ConditionsSale; - await database.SaveChangesAsync(ct); + await quotationsRepository.UpdateAsync(quotation, ct); - GetQuotationDto responseDto = new() - { - Id = quotation.Id, - Message = quotation.Message, - ConditionsSale = quotation.ConditionsSale, - GetQuotationProductDto = quotation.QuotationProducts.Select(qp => new GetQuotationProductDto - { - Quantity = qp.Quantity, - QuotationId = quotation.Id, - QuotationMessage = quotation.Message, - QuotationConditionsSale = quotation.ConditionsSale, - ProductId = qp.ProductId, - ProductReferences = qp.Product.Reference, - ProductName = qp.Product.Name, - ProductDuration = qp.Product.Duration, - ProductCaliber = qp.Product.Caliber, - ProductApprovalNumber = qp.Product.ApprovalNumber, - ProductWeight = qp.Product.Weight, - ProductNec = qp.Product.Nec, - ProductImage = qp.Product.Image, - ProductLink = qp.Product.Link, - ProductMinimalQuantity = qp.Product.MinimalQuantity, - }).ToList() - }; - await Send.OkAsync(responseDto, ct); + + await Send.OkAsync(mapper.Map(quotation), ct); } } \ No newline at end of file diff --git a/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs b/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs index 89ff725..37424e9 100644 --- a/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs +++ b/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs @@ -8,6 +8,7 @@ public sealed class GetQuotationByIdSpec : Specification public GetQuotationByIdSpec(int quotationId) { Query + .Include(q => q.QuotationProducts) .Where(x => x.Id == quotationId); } } \ No newline at end of file From 8325aa07685bc9a5082accb02ce229a6e9e2af0d Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 15:05:44 +0100 Subject: [PATCH 11/16] Refactored Setting --- .../Settings/CreateSettingEndpoint.cs | 16 ++++++-------- .../Settings/DeleteSettingEndpoint.cs | 9 ++++---- .../Endpoints/Settings/GetSettingEndpoint.cs | 17 +++++++-------- ...PatchSettingElectronicSignatureEndpoint.cs | 21 ++++++++----------- .../Settings/PatchSettingLogoEndpoint.cs | 19 +++++++---------- PyroFetes/Repositories/SettingsRepository.cs | 5 +++++ .../Settings/GetSettingByIdSpec.cs | 13 ++++++++++++ 7 files changed, 53 insertions(+), 47 deletions(-) create mode 100644 PyroFetes/Repositories/SettingsRepository.cs create mode 100644 PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs diff --git a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs index 1fd6ec9..0a6f1dd 100644 --- a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs @@ -2,10 +2,13 @@ using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; using PyroFetes.Models; +using PyroFetes.Repositories; namespace PyroFetes.Endpoints.Settings; -public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateSettingEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -21,15 +24,8 @@ public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint(setting), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs index 14fcac3..f608259 100644 --- a/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; @@ -9,7 +11,7 @@ public class DeleteSettingRequest public int Id { get; set; } } -public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint { public override void Configure() { @@ -19,7 +21,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); if (setting == null) { @@ -27,8 +29,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint +public class GetSettingEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -20,8 +24,7 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); if (setting == null) { @@ -29,12 +32,6 @@ public class GetSettingEndpoint(PyroFetesDbContext database) : Endpoint(setting), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs index b62776c..4e54c0e 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; -public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchSettingElectronicSignatureEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,8 +20,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) { - Setting? setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + if (setting == null) { await Send.NotFoundAsync(ct); @@ -25,15 +29,8 @@ public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database } setting.ElectronicSignature = req.ElectronicSignature; - await database.SaveChangesAsync(ct); + await settingsRepository.UpdateAsync(setting, ct); - GetSettingDto responseDto = new() - { - Id = setting.Id, - ElectronicSignature = setting.ElectronicSignature, - Logo = setting.Logo - }; - - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(setting), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs index ef974c7..99ff25a 100644 --- a/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.SettingDTO.Request; using PyroFetes.DTO.SettingDTO.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; namespace PyroFetes.Endpoints.Settings; -public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchSettingLogoEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,7 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); if (setting == null) { @@ -25,15 +29,8 @@ public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint(setting), ct); } } \ No newline at end of file diff --git a/PyroFetes/Repositories/SettingsRepository.cs b/PyroFetes/Repositories/SettingsRepository.cs new file mode 100644 index 0000000..5f4050b --- /dev/null +++ b/PyroFetes/Repositories/SettingsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class SettingsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs b/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs new file mode 100644 index 0000000..cc786e4 --- /dev/null +++ b/PyroFetes/Specifications/Settings/GetSettingByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Settings; + +public sealed class GetSettingByIdSpec : Specification +{ + public GetSettingByIdSpec(int settingId) + { + Query + .Where(setting => setting.Id == settingId); + } +} \ No newline at end of file From d64890dec95712ca694ffb33a47cfb83a579e9ae Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 15:11:14 +0100 Subject: [PATCH 12/16] Refactored Supplier --- .../Suppliers/CreateSupplierEndpoint.cs | 21 +++++------------ .../Suppliers/DeleteSupplierEndpoint.cs | 9 ++++---- .../Suppliers/GetAllSuppliersEndpoint.cs | 18 +++------------ .../Suppliers/GetSupplierEndpoint.cs | 22 ++++++------------ .../PatchSupplierDeleveryDelayEndpoint.cs | 18 +++++++-------- .../Suppliers/UpdateSupplierEndpoint.cs | 23 +++++++------------ 6 files changed, 37 insertions(+), 74 deletions(-) diff --git a/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs index 8ec116f..19f674c 100644 --- a/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs @@ -2,10 +2,13 @@ using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; using PyroFetes.Models; +using PyroFetes.Repositories; namespace PyroFetes.Endpoints.Suppliers; -public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -26,20 +29,8 @@ public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint(supplier), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs index 2f3dd5a..4aaef71 100644 --- a/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; namespace PyroFetes.Endpoints.Suppliers; @@ -9,7 +11,7 @@ public class DeleteSupplierRequest public int Id { get; set; } } -public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : Endpoint { public override void Configure() { @@ -19,7 +21,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); if (supplier == null) { @@ -27,8 +29,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint> +public class GetAllSuppliersEndpoint(SuppliersRepository suppliersRepository) : EndpointWithoutRequest> { public override void Configure() { @@ -14,19 +15,6 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWith public override async Task HandleAsync(CancellationToken ct) { - List supplier = await database.Suppliers - .Select(supplier => new GetSupplierDto() - { - Id = supplier.Id, - Name = supplier.Name, - Email = supplier.Email, - Phone = supplier.Phone, - Address = supplier.Address, - City = supplier.City, - ZipCode = supplier.ZipCode, - DeliveryDelay = supplier.DeliveryDelay - }).ToListAsync(ct); - - await Send.OkAsync(supplier, ct); + await Send.OkAsync(await suppliersRepository.ProjectToListAsync(ct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs index 628969d..7c6377a 100644 --- a/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; namespace PyroFetes.Endpoints.Suppliers; @@ -10,7 +12,9 @@ public class GetSupplierRequest public int Id { get; set; } } -public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class GetSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -20,8 +24,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); if (supplier == null) { @@ -29,17 +32,6 @@ public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint(supplier), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs index 85d4040..f4ece04 100644 --- a/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; namespace PyroFetes.Endpoints.Suppliers; -public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchSupplierDeleveryDelayEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,7 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) { - Supplier? supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); if (supplier == null) { @@ -25,14 +29,8 @@ public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : E } supplier.DeliveryDelay = req.DeliveryDelay; - await database.SaveChangesAsync(ct); - - GetSupplierDto responseDto = new() - { - Id = supplier.Id, - DeliveryDelay = supplier.DeliveryDelay, - }; + await suppliersRepository.UpdateAsync(supplier, ct); - await Send.OkAsync(responseDto, ct); + await Send.OkAsync(mapper.Map(supplier), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs index e9c4ef4..0ef1516 100644 --- a/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; namespace PyroFetes.Endpoints.Suppliers; -public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); if (supplier == null) { @@ -31,20 +35,9 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint(supplier), ct); } } \ No newline at end of file From 0b7254914383ba78f90fa3aa681f51cdac2e3f64 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 15:20:13 +0100 Subject: [PATCH 13/16] Refactored Program.cs --- .../CreatePurchaseProductEndpoint.cs | 15 ++++++++------- PyroFetes/Program.cs | 13 ++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs index 464f1f2..73aa788 100644 --- a/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs @@ -29,9 +29,10 @@ public class CreatePurchaseProductEndpoint( await Send.NotFoundAsync(ct); return; } - - PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct); - + + PurchaseOrder? purchaseOrder = + await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct); + if (purchaseOrder == null) { purchaseOrder = new PurchaseOrder() @@ -40,16 +41,16 @@ public class CreatePurchaseProductEndpoint( }; 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(purchaseProduct), ct); } -} +} \ No newline at end of file diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 2b82940..102bf2d 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -5,7 +5,7 @@ using FastEndpoints; using FastEndpoints.Swagger; using FastEndpoints.Security; using PyroFetes.MappingProfiles; -using IMapper = FastEndpoints.IMapper; +using PyroFetes.Repositories; WebApplicationBuilder builder = WebApplication.CreateBuilder(args); @@ -19,6 +19,17 @@ builder.Services // On ajoute ici la configuration de la base de données builder.Services.AddDbContext(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); MapperConfiguration mappingConfig = new(mc => { From 165c9b9322f8df078bb29839eee428992acd14ab Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 15:38:53 +0100 Subject: [PATCH 14/16] Refactored User --- .../Endpoints/Users/ConnectUserEndpoint.cs | 6 +++-- .../Endpoints/Users/CreateUserEndpoint.cs | 21 +++++----------- .../Endpoints/Users/DeleteUserEndpoint.cs | 9 +++---- .../Endpoints/Users/GetAllUsersEndpoint.cs | 17 +++---------- PyroFetes/Endpoints/Users/GetUserEndpoint.cs | 21 ++++++---------- .../Users/PatchUserPasswordEndpoint.cs | 24 ++++++++----------- .../Endpoints/Users/UpdateUserEndpoint.cs | 23 +++++++----------- PyroFetes/Program.cs | 1 + PyroFetes/Repositories/UsersRepository.cs | 5 ++++ .../Specifications/Users/GetUserByIdSpec.cs | 13 ++++++++++ .../Specifications/Users/GetUserByNameSpec.cs | 13 ++++++++++ 11 files changed, 76 insertions(+), 77 deletions(-) create mode 100644 PyroFetes/Repositories/UsersRepository.cs create mode 100644 PyroFetes/Specifications/Users/GetUserByIdSpec.cs create mode 100644 PyroFetes/Specifications/Users/GetUserByNameSpec.cs diff --git a/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs index 7ddff69..916f41e 100644 --- a/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs @@ -4,10 +4,12 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; namespace PyroFetes.Endpoints.Users; -public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint +public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint { public override void Configure() { @@ -17,7 +19,7 @@ public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint x.Name == req.Name, ct); + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct); if (user == null) { diff --git a/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs b/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs index a923b4e..1c2d261 100644 --- a/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs @@ -3,10 +3,13 @@ using PasswordGenerator; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; using PyroFetes.Models; +using PyroFetes.Repositories; namespace PyroFetes.Endpoints.Users; -public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -27,20 +30,8 @@ public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs index d5b0b62..d6df7d3 100644 --- a/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs @@ -1,6 +1,8 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; namespace PyroFetes.Endpoints.Users; @@ -9,7 +11,7 @@ public class DeleteUserRequest public int Id { get; set; } } -public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint { public override void Configure() { @@ -19,7 +21,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); if (user == null) { @@ -27,8 +29,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint> +public class GetAllUsersEndpoint(UsersRepository usersRepository) : EndpointWithoutRequest> { public override void Configure() { @@ -14,18 +15,6 @@ public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutR public override async Task HandleAsync(CancellationToken ct) { - List users = await database.Users - .Select(users => new GetUserDto() - { - Id = users.Id, - Name = users.Name, - Password = users.Password, - Salt = users.Salt, - Email = users.Email, - Fonction = users.Fonction - }) - .ToListAsync(ct); - - await Send.OkAsync(users, ct); + await Send.OkAsync(await usersRepository.ProjectToListAsync(ct), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Users/GetUserEndpoint.cs b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs index 3bcc589..222079d 100644 --- a/PyroFetes/Endpoints/Users/GetUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; namespace PyroFetes.Endpoints.Users; @@ -10,7 +12,9 @@ public class GetUserRequest public int Id { get; set; } } -public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint +public class GetUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -20,8 +24,7 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); if (user == null) { @@ -29,16 +32,6 @@ public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs index 17e5af8..6f7491e 100644 --- a/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs +++ b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs @@ -3,10 +3,14 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; namespace PyroFetes.Endpoints.Users; -public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint +public class PatchUserPasswordEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,7 +20,8 @@ public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint

x.Id == req.Id, ct); + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); + if (user == null) { await Send.NotFoundAsync(ct); @@ -24,17 +29,8 @@ public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint

(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs index 20bb3d4..cf5f8d6 100644 --- a/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs @@ -4,10 +4,14 @@ using PasswordGenerator; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; namespace PyroFetes.Endpoints.Users; -public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -17,8 +21,8 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint x.Id == req.Id, ct); - User? ckeckName = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct); + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); + User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct); if (user == null) { @@ -39,18 +43,9 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 102bf2d..21f864b 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -30,6 +30,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); MapperConfiguration mappingConfig = new(mc => { diff --git a/PyroFetes/Repositories/UsersRepository.cs b/PyroFetes/Repositories/UsersRepository.cs new file mode 100644 index 0000000..b943703 --- /dev/null +++ b/PyroFetes/Repositories/UsersRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class UsersRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/Users/GetUserByIdSpec.cs b/PyroFetes/Specifications/Users/GetUserByIdSpec.cs new file mode 100644 index 0000000..db5c0be --- /dev/null +++ b/PyroFetes/Specifications/Users/GetUserByIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Users; + +public sealed class GetUserByIdSpec : Specification +{ + public GetUserByIdSpec(int userId) + { + Query + .Where(x => x.Id == userId); + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/Users/GetUserByNameSpec.cs b/PyroFetes/Specifications/Users/GetUserByNameSpec.cs new file mode 100644 index 0000000..daa75ad --- /dev/null +++ b/PyroFetes/Specifications/Users/GetUserByNameSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Users; + +public sealed class GetUserByNameSpec : Specification +{ + public GetUserByNameSpec(string userName) + { + Query + .Where(x=> x.Name == userName); + } +} \ No newline at end of file From 669938d67794bea124402f9ac833df88a278e757 Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 16:09:04 +0100 Subject: [PATCH 15/16] Refactored WarehouseProduct --- .../WareHouseProducts/GetTotalQuantityEndpoint.cs | 14 ++++++++------ PyroFetes/Program.cs | 1 + PyroFetes/Repositories/PyrofetesRepository.cs | 4 ++-- .../Repositories/WarehouseProductsRepository.cs | 5 +++++ .../GetProductTotalQuantitySpec.cs | 14 ++++++++++++++ .../GetWarehouseProductByProductIdSpec.cs | 13 +++++++++++++ 6 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 PyroFetes/Repositories/WarehouseProductsRepository.cs create mode 100644 PyroFetes/Specifications/WarehouseProducts/GetProductTotalQuantitySpec.cs create mode 100644 PyroFetes/Specifications/WarehouseProducts/GetWarehouseProductByProductIdSpec.cs diff --git a/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs index a6398c8..2a5c8a8 100644 --- a/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs @@ -2,6 +2,8 @@ using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.WareHouseProduct.Response; using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.WarehouseProducts; namespace PyroFetes.Endpoints.WareHouseProducts; @@ -10,7 +12,8 @@ public class GetTotalQuantityRequest public int ProductId { get; set; } } -public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint +public class GetTotalQuantityEndpoint( + WarehouseProductsRepository warehouseProductsRepository) : Endpoint { public override void Configure() { @@ -20,8 +23,7 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint wp.ProductId == req.ProductId, ct); + bool exists = await warehouseProductsRepository.AnyAsync(new GetWarehouseProductByProductIdSpec(req.ProductId), ct); if (!exists) { @@ -29,9 +31,9 @@ public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint wp.ProductId == req.ProductId) - .SumAsync(wp => wp.Quantity, ct); + int totalQuantity = + await warehouseProductsRepository.SumAsync(new GetProductTotalQuantitySpec(req.ProductId), + wp => wp.Quantity, ct); GetTotalQuantityDto responseDto = new() { diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 21f864b..1251820 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -31,6 +31,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); MapperConfiguration mappingConfig = new(mc => { diff --git a/PyroFetes/Repositories/PyrofetesRepository.cs b/PyroFetes/Repositories/PyrofetesRepository.cs index 0f09bd3..baebacc 100644 --- a/PyroFetes/Repositories/PyrofetesRepository.cs +++ b/PyroFetes/Repositories/PyrofetesRepository.cs @@ -59,9 +59,9 @@ public class PyrofetesRepository(DbContext databaseContext, AutoMapper.IMappe /// /// /// - public async Task SumAsync( + public async Task SumAsync( ISpecification specification, - Expression> selector, + Expression> selector, CancellationToken cancellationToken = default) { return await ApplySpecification(specification).SumAsync(selector, cancellationToken); diff --git a/PyroFetes/Repositories/WarehouseProductsRepository.cs b/PyroFetes/Repositories/WarehouseProductsRepository.cs new file mode 100644 index 0000000..e53207a --- /dev/null +++ b/PyroFetes/Repositories/WarehouseProductsRepository.cs @@ -0,0 +1,5 @@ +using PyroFetes.Models; + +namespace PyroFetes.Repositories; + +public class WarehouseProductsRepository(PyroFetesDbContext pyrofetesContext, AutoMapper.IMapper mapper) : PyrofetesRepository(pyrofetesContext, mapper); \ No newline at end of file diff --git a/PyroFetes/Specifications/WarehouseProducts/GetProductTotalQuantitySpec.cs b/PyroFetes/Specifications/WarehouseProducts/GetProductTotalQuantitySpec.cs new file mode 100644 index 0000000..9dd451f --- /dev/null +++ b/PyroFetes/Specifications/WarehouseProducts/GetProductTotalQuantitySpec.cs @@ -0,0 +1,14 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.WarehouseProducts; + +public sealed class GetProductTotalQuantitySpec : Specification +{ + public GetProductTotalQuantitySpec(int productId) + { + Query + .Where(wp => wp.ProductId == productId); + + } +} \ No newline at end of file diff --git a/PyroFetes/Specifications/WarehouseProducts/GetWarehouseProductByProductIdSpec.cs b/PyroFetes/Specifications/WarehouseProducts/GetWarehouseProductByProductIdSpec.cs new file mode 100644 index 0000000..ff135c1 --- /dev/null +++ b/PyroFetes/Specifications/WarehouseProducts/GetWarehouseProductByProductIdSpec.cs @@ -0,0 +1,13 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.WarehouseProducts; + +public sealed class GetWarehouseProductByProductIdSpec : Specification +{ + public GetWarehouseProductByProductIdSpec(int productId) + { + Query + .Where(x => x.ProductId == productId); + } +} \ No newline at end of file From b76b6680979907100848e4f2a846ba442cb8392b Mon Sep 17 00:00:00 2001 From: Cristiano Date: Thu, 20 Nov 2025 16:12:16 +0100 Subject: [PATCH 16/16] Addapted to use cors and optimized connection with the frontend --- PyroFetes/Program.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 1251820..e1a719b 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -14,7 +14,20 @@ builder.Services .AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong") .AddAuthorization() .AddFastEndpoints() - .SwaggerDocument(); + .SwaggerDocument(options => + { + options.ShortSchemaNames = true; + }) + .AddCors(options => + { + options.AddDefaultPolicy(policyBuilder => + { + policyBuilder + .WithOrigins("http://localhost:4200") + .WithMethods("GET", "POST", "PUT", "DELETE", "PATCH") + .AllowAnyHeader(); + }); + }); // On ajoute ici la configuration de la base de données builder.Services.AddDbContext(); @@ -48,9 +61,15 @@ builder.Services.AddSingleton(mapper); WebApplication app = builder.Build(); app.UseAuthentication() .UseAuthorization() - .UseFastEndpoints() + .UseFastEndpoints(options => + { + options.Endpoints.ShortNames = true; + options.Endpoints.RoutePrefix = "API"; + }) .UseSwaggerGen(); app.UseHttpsRedirection(); +app.UseCors(); + app.Run(); \ No newline at end of file