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/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/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/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 d7f67ff..16502ac 100644 --- a/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs +++ b/PyroFetes/Endpoints/Deliverers/CreateDelivererEndpoint.cs @@ -7,14 +7,13 @@ using PyroFetes.Repositories; namespace PyroFetes.Endpoints.Deliverers; public class CreateDelivererEndpoint( - DeliverersRepository deliverersRepository, + DeliverersRepository deliverersRepository, AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { 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 new file mode 100644 index 0000000..1e2c0f3 --- /dev/null +++ b/PyroFetes/Endpoints/DeliveryNotes/CreateDeliveryNoteEndpoint.cs @@ -0,0 +1,68 @@ +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"); + AllowAnonymous(); + } + + 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!) + { + 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/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/Endpoints/Price/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Price/CreatePriceEndpoint.cs deleted file mode 100644 index 43934a6..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.NotFoundAsync(ct); //"Le fournisseur a déjà un prix pour ce produit.", - 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/Price/PatchPriceEndpoint.cs b/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs deleted file mode 100644 index 05dbdb8..0000000 --- a/PyroFetes/Endpoints/Price/PatchPriceEndpoint.cs +++ /dev/null @@ -1,36 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Price.Request; -using PyroFetes.DTO.Price.Response; - -namespace PyroFetes.Endpoints.Price; - -public class PatchPriceEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId }); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct) - { - var price = await database.Prices.SingleOrDefaultAsync(p => p.ProductId == req.ProductId && p.SupplierId == req.SupplierId, ct); - if (price == null) - { - await Send.NotFoundAsync(ct); - return; - } - - price.SellingPrice = req.SellingPrice; - await database.SaveChangesAsync(ct); - - GetPriceDto responseDto = new() - { - ProductId = price.ProductId, - SupplierId = price.SupplierId, - SellingPrice = price.SellingPrice - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs new file mode 100644 index 0000000..3a71e9c --- /dev/null +++ b/PyroFetes/Endpoints/Prices/CreatePriceEndpoint.cs @@ -0,0 +1,84 @@ +using FastEndpoints; +using PyroFetes.DTO.Price.Request; +using PyroFetes.DTO.Price.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Prices; +using PyroFetes.Specifications.Products; +using PyroFetes.Specifications.Suppliers; + +namespace PyroFetes.Endpoints.Prices; + +public class CreatePriceEndpoint( + SuppliersRepository suppliersRepository, + ProductsRepository productsRepository, + PricesRepository pricesRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/prices"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct) + { + // Gestion du fournisseur + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.SupplierId), ct); + if (supplier == null) + { + supplier = new Supplier() + { + Name = req.SupplierName, + Email = req.SupplierEmail, + Phone = req.SupplierPhone, + Address = req.SupplierAddress, + City = req.SupplierCity, + ZipCode = req.SupplierZipCode, + DeliveryDelay = req.SupplierDeliveryDelay + }; + await suppliersRepository.AddAsync(supplier, ct); + } + + // Gestion du produit + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + if (product == null) + { + product = new Product() + { + Reference = req.ProductReferences, + Name = req.ProductName, + Duration = req.ProductDuration, + Caliber = req.ProductCaliber, + ApprovalNumber = req.ProductApprovalNumber, + Weight = req.ProductWeight, + Nec = req.ProductNec, + Image = req.ProductImage, + Link = req.ProductLink, + MinimalQuantity = req.ProductMinimalQuantity + }; + await productsRepository.AddAsync(product, ct); + } + + // Vérifie si le prix existe déjà pour ce fournisseur et produit + Price? existingPrice = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId), ct); + + if (existingPrice != null) + { + await Send.StringAsync("Le fournisseur a déjà un prix pour ce produit.", 400, cancellation: ct); + return; + } + + // Création du prix + var priceAdded = new Price() + { + SellingPrice = req.SellingPrice, + SupplierId = supplier.Id, + ProductId = product.Id + }; + await pricesRepository.AddAsync(priceAdded, ct); + + + await Send.OkAsync(mapper.Map(priceAdded), ct); + } +} diff --git a/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs similarity index 59% rename from PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs rename to PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs index bb289c9..260c7cb 100644 --- a/PyroFetes/Endpoints/Price/DeletePriceEndpoint.cs +++ b/PyroFetes/Endpoints/Prices/DeletePriceEndpoint.cs @@ -1,7 +1,10 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Prices; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.Prices; public class DeletePriceRequest { @@ -9,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() { @@ -19,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) { @@ -28,8 +30,7 @@ public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint +{ + public override void Configure() + { + Patch("/api/prices/{@ProductId}/{@SupplierId}/SellingPrice", x => new { x.ProductId, x.SupplierId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchPriceSellingPriceDto req, CancellationToken ct) + { + Price? price = await pricesRepository.FirstOrDefaultAsync(new GetPriceByProductIdAndSupplierIdSpec(req.ProductId, req.SupplierId),ct); + + if (price == null) + { + await Send.NotFoundAsync(ct); + return; + } + + price.SellingPrice = req.SellingPrice; + + await pricesRepository.UpdateAsync(price, ct); + + await Send.OkAsync(mapper.Map(price), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs deleted file mode 100644 index faedfa5..0000000 --- a/PyroFetes/Endpoints/Product/GetAllProductsEndpoint.cs +++ /dev/null @@ -1,37 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.Product; - -public class GetAllProductsEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> -{ - public override void Configure() - { - Get("/api/products"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CancellationToken ct) - { - var 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs b/PyroFetes/Endpoints/Product/GetProductEndpoint.cs deleted file mode 100644 index f35a6a6..0000000 --- a/PyroFetes/Endpoints/Product/GetProductEndpoint.cs +++ /dev/null @@ -1,49 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.Product; - -public class GetProductRequest -{ - public int Id { get; set; } -} - -public class GetProductEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/products/{@Id}", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(GetProductRequest req, CancellationToken ct) - { - var product = await database.Products - .SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (product == null) - { - await Send.NotFoundAsync(ct); - return; - } - - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs deleted file mode 100644 index 31ad504..0000000 --- a/PyroFetes/Endpoints/Product/PatchProductMinimalStockEndpoint.cs +++ /dev/null @@ -1,46 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Product.Request; -using PyroFetes.DTO.Product.Response; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.Product; - -public class PatchProductMinimalStockEndpoint(PyroFetesDbContext database) - : Endpoint -{ - public override void Configure() - { - Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id }); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) - { - var product = await database.Products.SingleOrDefaultAsync(po => po.Id == req.Id, ct); - if (product == null) - { - await Send.NotFoundAsync(ct); - return; - } - - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs new file mode 100644 index 0000000..46b6c7d --- /dev/null +++ b/PyroFetes/Endpoints/Products/GetAllProductsEndpoint.cs @@ -0,0 +1,21 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.Products; + +public class GetAllProductsEndpoint(ProductsRepository productsRepository) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("/api/products"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken 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 new file mode 100644 index 0000000..7e458a3 --- /dev/null +++ b/PyroFetes/Endpoints/Products/GetProductEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; + +namespace PyroFetes.Endpoints.Products; + +public class GetProductRequest +{ + public int Id { get; set; } +} + +public class GetProductEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/products/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetProductRequest req, CancellationToken ct) + { + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); + + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await Send.OkAsync(mapper.Map(product), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs new file mode 100644 index 0000000..51bfd1d --- /dev/null +++ b/PyroFetes/Endpoints/Products/PatchProductMinimalStockEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Product.Request; +using PyroFetes.DTO.Product.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; + +namespace PyroFetes.Endpoints.Products; + +public class PatchProductMinimalStockEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/products/{@Id}/MinimalStock", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchProductMinimalStockDto req, CancellationToken ct) + { + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.Id), ct); + + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + product.MinimalQuantity = req.MinimalQuantity; + await productsRepository.UpdateAsync(product, ct); + + await Send.OkAsync(mapper.Map(product), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs similarity index 52% rename from PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs rename to PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs index 43c4e1f..83df9ac 100644 --- a/PyroFetes/Endpoints/Product/UpdateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Products/UpdateProductEndpoint.cs @@ -2,10 +2,15 @@ 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.Product; +namespace PyroFetes.Endpoints.Products; -public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateProductEndpoint( + ProductsRepository productsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -15,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) { @@ -33,23 +38,9 @@ public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint(product), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs deleted file mode 100644 index 8c09819..0000000 --- a/PyroFetes/Endpoints/PurchaseOrder/GetAllPurchaseOrderEndpoint.cs +++ /dev/null @@ -1,46 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseOrder.Response; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.PurchaseOrder; - -public class GetAllPurchaseOrderEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> -{ - public override void Configure() - { - Get("/api/purchaseOrders"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CancellationToken ct) - { - var 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs deleted file mode 100644 index 59e3332..0000000 --- a/PyroFetes/Endpoints/PurchaseOrder/GetPurchaseOrderEndpoint.cs +++ /dev/null @@ -1,57 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseOrder.Response; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.PurchaseOrder; - -public class GetPurchaseOrderRequest -{ - public int Id { get; set; } -} - -public class GetPurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/purchaseOrders/{@Id}", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct) - { - var purchaseOrder = await database.PurchaseOrders - .SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (purchaseOrder == null) - { - await Send.NotFoundAsync(ct); - return; - } - - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs deleted file mode 100644 index a6bbff0..0000000 --- a/PyroFetes/Endpoints/PurchaseOrder/PatchPurchaseOrderPurchaseConditionsEndpoint.cs +++ /dev/null @@ -1,54 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseOrder.Request; -using PyroFetes.DTO.PurchaseOrder.Response; -using PyroFetes.DTO.PurchaseProduct.Request; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.PurchaseOrder; - -public class PatchPurchaseOrderPurchaseConditionsEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id }); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct) - { - var purchaseOrder = await database.PurchaseOrders.SingleOrDefaultAsync(po => po.Id == req.Id, ct); - if (purchaseOrder == null) - { - await Send.NotFoundAsync(ct); - return; - } - - purchaseOrder.PurchaseConditions = req.PurchaseConditions; - await database.SaveChangesAsync(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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs similarity index 51% rename from PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs rename to PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs index a6a990a..23098d8 100644 --- a/PyroFetes/Endpoints/PurchaseOrder/DeletePurchaseOrderEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseOrders/DeletePurchaseOrderEndpoint.cs @@ -1,14 +1,19 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; -namespace PyroFetes.Endpoints.PurchaseOrder; +namespace PyroFetes.Endpoints.PurchaseOrders; 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() { @@ -18,9 +23,7 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseOrderRequest req, CancellationToken ct) { - var 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) { @@ -30,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 new file mode 100644 index 0000000..f60fc95 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseOrders/GetAllPurchaseOrderEndpoint.cs @@ -0,0 +1,21 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseOrder.Response; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.PurchaseOrders; + +public class GetAllPurchaseOrderEndpoint(PurchaseOrdersRepository purchaseOrdersRepository) : EndpointWithoutRequest> +{ + public override void Configure() + { + Get("/api/purchaseOrders"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken 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 new file mode 100644 index 0000000..16823ed --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseOrders/GetPurchaseOrderEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseOrder.Response; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; + +namespace PyroFetes.Endpoints.PurchaseOrders; + +public class GetPurchaseOrderRequest +{ + public int Id { get; set; } +} + +public class GetPurchaseOrderEndpoint( + PurchaseOrdersRepository purchaseOrdersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/purchaseOrders/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetPurchaseOrderRequest req, CancellationToken ct) + { + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); + + if (purchaseOrder == null) + { + await Send.NotFoundAsync(ct); + return; + } + + 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 new file mode 100644 index 0000000..c422f4a --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseOrders/PatchPurchaseOrderPurchaseConditionsEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseOrder.Request; +using PyroFetes.DTO.PurchaseOrder.Response; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseOrders; + +namespace PyroFetes.Endpoints.PurchaseOrders; + +public class PatchPurchaseOrderPurchaseConditionsEndpoint( + PurchaseOrdersRepository purchaseOrdersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/purchaseOrders/{@Id}/PurchaseConditions", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchPurchaseOrderPurchaseConditionsDto req, CancellationToken ct) + { + PurchaseOrder? purchaseOrder = await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.Id), ct); + if (purchaseOrder == null) + { + await Send.NotFoundAsync(ct); + return; + } + + purchaseOrder.PurchaseConditions = req.PurchaseConditions; + await purchaseOrdersRepository.UpdateAsync(purchaseOrder, ct); + + await Send.OkAsync(mapper.Map(purchaseOrder), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs deleted file mode 100644 index f060c3a..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/CreatePurchaseProductEndpoint.cs +++ /dev/null @@ -1,67 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using FastEndpoints; -using PyroFetes.DTO.PurchaseProduct.Request; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class CreatePurchaseProductEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Post("/api/purchaseProducts"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) - { - var 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); - - if (purchaseOrder == null) - { - purchaseOrder = new Models.PurchaseOrder() - { - PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" - }; - database.PurchaseOrders.Add(purchaseOrder); - await database.SaveChangesAsync(ct); - } - - var purchaseProduct = new Models.PurchaseProduct() - { - ProductId = product.Id, - PurchaseOrderId = purchaseOrder.Id, - Quantity = req.Quantity - }; - database.PurchaseProducts.Add(purchaseProduct); - await database.SaveChangesAsync(ct); - - var 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); - } -} diff --git a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs b/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs deleted file mode 100644 index 952dd8d..0000000 --- a/PyroFetes/Endpoints/PurchaseProduct/PatchPurchaseProductQuantityEndpoint.cs +++ /dev/null @@ -1,36 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseProduct.Request; -using PyroFetes.DTO.PurchaseProduct.Response; - -namespace PyroFetes.Endpoints.PurchaseProduct; - -public class PatchPurchaseProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId }); - AllowAnonymous(); - } - - 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); - if (purchaseProduct == null) - { - await Send.NotFoundAsync(ct); - return; - } - - purchaseProduct.Quantity = req.Quantity; - await database.SaveChangesAsync(ct); - - GetPurchaseProductDto responseDto = new() - { - ProductId = purchaseProduct.ProductId, - PurchaseOrderId = purchaseProduct.PurchaseOrderId, - Quantity = purchaseProduct.Quantity - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs new file mode 100644 index 0000000..73aa788 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProducts/CreatePurchaseProductEndpoint.cs @@ -0,0 +1,56 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; +using PyroFetes.Specifications.PurchaseOrders; + +namespace PyroFetes.Endpoints.PurchaseProducts; + +public class CreatePurchaseProductEndpoint( + ProductsRepository productsRepository, + PurchaseOrdersRepository purchaseOrdersRepository, + PurchaseProductsRepository purchaseProductsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/purchaseProducts"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreatePurchaseProductDto req, CancellationToken ct) + { + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + PurchaseOrder? purchaseOrder = + await purchaseOrdersRepository.FirstOrDefaultAsync(new GetPurchaseOrderByIdSpec(req.PurchaseOrderId), ct); + + if (purchaseOrder == null) + { + purchaseOrder = new PurchaseOrder() + { + PurchaseConditions = req.PurchaseOrderPurchaseConditions ?? "Conditions non précisées" + }; + await purchaseOrdersRepository.AddAsync(purchaseOrder, ct); + } + + PurchaseProduct purchaseProduct = new PurchaseProduct() + { + ProductId = product.Id, + PurchaseOrderId = purchaseOrder.Id, + Quantity = req.Quantity + }; + + await purchaseProductsRepository.AddAsync(purchaseProduct, ct); + + await Send.OkAsync(mapper.Map(purchaseProduct), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs similarity index 54% rename from PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs rename to PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs index 93d60fb..811cade 100644 --- a/PyroFetes/Endpoints/PurchaseProduct/DeletePurchaseProductEndpoint.cs +++ b/PyroFetes/Endpoints/PurchaseProducts/DeletePurchaseProductEndpoint.cs @@ -1,7 +1,10 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseProducts; -namespace PyroFetes.Endpoints.PurchaseProduct; +namespace PyroFetes.Endpoints.PurchaseProducts; public class DeletePurchaseProductRequest { @@ -9,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() { @@ -19,8 +22,8 @@ public class DeletePurchaseOrderEndpoint(PyroFetesDbContext database) : Endpoint public override async Task HandleAsync(DeletePurchaseProductRequest req, CancellationToken ct) { - var 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) { @@ -28,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 new file mode 100644 index 0000000..17a88c4 --- /dev/null +++ b/PyroFetes/Endpoints/PurchaseProducts/PatchPurchaseProductQuantityEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.PurchaseProduct.Request; +using PyroFetes.DTO.PurchaseProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.PurchaseProducts; + +namespace PyroFetes.Endpoints.PurchaseProducts; + +public class PatchPurchaseProductQuantityEndpoint( + PurchaseProductsRepository purchaseProductsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/purchaseProducts/{@ProductId}/{@PurchaseOrderId}/Quantity", x => new { x.ProductId, x.PurchaseOrderId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchPurchaseProductQuantityDto req, CancellationToken ct) + { + PurchaseProduct? purchaseProduct = + await purchaseProductsRepository.FirstOrDefaultAsync( + new GetPurchaseProductByProductIdAndPurchaseOrderIdSpec(req.ProductId, req.PurchaseOrderId), ct); + + if (purchaseProduct == null) + { + await Send.NotFoundAsync(ct); + return; + } + + purchaseProduct.Quantity = req.Quantity; + await purchaseProductsRepository.UpdateAsync(purchaseProduct, ct); + + await Send.OkAsync(mapper.Map(purchaseProduct), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs deleted file mode 100644 index 1a7dfb9..0000000 --- a/PyroFetes/Endpoints/Quotation/GetAllQuotationEndpoint.cs +++ /dev/null @@ -1,49 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Quotation.Response; -using PyroFetes.DTO.QuotationProduct.Response; - -namespace PyroFetes.Endpoints.Quotation; - -public class GetAllQuotationEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> -{ - public override void Configure() - { - Get("/api/quotations"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CancellationToken ct) - { - var 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs deleted file mode 100644 index 01654ef..0000000 --- a/PyroFetes/Endpoints/Quotation/GetQuotationEndpoint.cs +++ /dev/null @@ -1,60 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Quotation.Response; -using PyroFetes.DTO.QuotationProduct.Response; - -namespace PyroFetes.Endpoints.Quotation; - -public class GetQuotationRequest -{ - public int Id { get; set; } -} - -public class GetQuotationEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/quotations/{@Id}", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct) - { - var quotation = await database.Quotations - .SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (quotation == null) - { - await Send.NotFoundAsync(ct); - return; - } - - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs b/PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs deleted file mode 100644 index 8cc9609..0000000 --- a/PyroFetes/Endpoints/Quotation/PatchQuotationConditionsSaleEndpoint.cs +++ /dev/null @@ -1,58 +0,0 @@ -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; - -namespace PyroFetes.Endpoints.Quotation; - -public class PatchQuotationConditionsSaleEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id }); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct) - { - var quotation = await database.Quotations.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - if (quotation == null) - { - await Send.NotFoundAsync(ct); - return; - } - - quotation.ConditionsSale = req.ConditionsSale; - await database.SaveChangesAsync(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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs deleted file mode 100644 index ada8499..0000000 --- a/PyroFetes/Endpoints/QuotationProduct/CreateQuotationProductEndpoint.cs +++ /dev/null @@ -1,68 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.QuotationProduct.Request; -using PyroFetes.DTO.QuotationProduct.Response; - -namespace PyroFetes.Endpoints.QuotationProduct; - -public class CreateQuotationProductEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Post("/api/quotationProduct"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct) - { - var 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); - - if (quotation == null) - { - quotation = new Models.Quotation() - { - Message = req.QuotationMessage ?? "", - ConditionsSale = req.QuotationConditionsSale, - }; - database.Quotations.Add(quotation); - await database.SaveChangesAsync(ct); - } - - var quotationProduct = new Models.QuotationProduct() - { - ProductId = product.Id, - QuotationId = quotation.Id, - Quantity = req.Quantity - }; - database.QuotationProducts.Add(quotationProduct); - await database.SaveChangesAsync(ct); - - var 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 Send.OkAsync(responseDto, ct); - } -} diff --git a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs b/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs deleted file mode 100644 index 33c050e..0000000 --- a/PyroFetes/Endpoints/QuotationProduct/PatchQuotationProductQuantityEndpoint.cs +++ /dev/null @@ -1,36 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.QuotationProduct.Request; -using PyroFetes.DTO.QuotationProduct.Response; - -namespace PyroFetes.Endpoints.QuotationProduct; - -public class PatchQuotationProductQuantityEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId }); - AllowAnonymous(); - } - - 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); - if (quotationProduct == null) - { - await Send.NotFoundAsync(ct); - return; - } - - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs new file mode 100644 index 0000000..0c64357 --- /dev/null +++ b/PyroFetes/Endpoints/QuotationProducts/CreateQuotationProductEndpoint.cs @@ -0,0 +1,58 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.QuotationProduct.Request; +using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Products; +using PyroFetes.Specifications.Quotations; + +namespace PyroFetes.Endpoints.QuotationProducts; + +public class CreateQuotationProductEndpoint( + QuotationProductsRepository quotationProductsRepository, + ProductsRepository productsRepository, + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/quotationProduct"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateQuotationProductDto req, CancellationToken ct) + { + Product? product = await productsRepository.FirstOrDefaultAsync(new GetProductByIdSpec(req.ProductId), ct); + + if (product == null) + { + await Send.NotFoundAsync(ct); + return; + } + + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.QuotationId), ct); + + if (quotation == null) + { + quotation = new Quotation() + { + Message = req.QuotationMessage ?? "", + ConditionsSale = req.QuotationConditionsSale, + }; + + await quotationsRepository.AddAsync(quotation, ct); + } + + QuotationProduct quotationProduct = new QuotationProduct() + { + ProductId = product.Id, + QuotationId = quotation.Id, + Quantity = req.Quantity + }; + + await quotationProductsRepository.AddAsync(quotationProduct, ct); + + await Send.OkAsync(mapper.Map(quotationProduct), ct); + } +} diff --git a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs similarity index 52% rename from PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs rename to PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs index aa480e8..c680325 100644 --- a/PyroFetes/Endpoints/QuotationProduct/DeleteQuotationProductEndpoint.cs +++ b/PyroFetes/Endpoints/QuotationProducts/DeleteQuotationProductEndpoint.cs @@ -1,7 +1,10 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.QuotationProducts; -namespace PyroFetes.Endpoints.QuotationProduct; +namespace PyroFetes.Endpoints.QuotationProducts; public class DeleteQuotationProductRequest { @@ -9,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() { @@ -19,8 +22,9 @@ public class DeleteQuotationProductEndpoint(PyroFetesDbContext database) : Endpo public override async Task HandleAsync(DeleteQuotationProductRequest req, CancellationToken ct) { - var 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) { @@ -28,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 new file mode 100644 index 0000000..26f3691 --- /dev/null +++ b/PyroFetes/Endpoints/QuotationProducts/PatchQuotationProductQuantityEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.QuotationProduct.Request; +using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.QuotationProducts; + +namespace PyroFetes.Endpoints.QuotationProducts; + +public class PatchQuotationProductQuantityEndpoint( + QuotationProductsRepository quotationProductsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/quotationProduct/{@ProductId}/{@QuotationId}/Quantity", x => new { x.ProductId, x.QuotationId }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchQuotationProductQuantityDto req, CancellationToken ct) + { + QuotationProduct? quotationProduct = + await quotationProductsRepository.FirstOrDefaultAsync( + new GetQuotationProductByProductIdAndQuotationIdSpec(req.ProductId, req.QuotationId), ct); + if (quotationProduct == null) + { + await Send.NotFoundAsync(ct); + return; + } + + quotationProduct.Quantity = req.Quantity; + await quotationProductsRepository.UpdateAsync(quotationProduct, ct); + + await Send.OkAsync(mapper.Map(quotationProduct), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs similarity index 52% rename from PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs rename to PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs index e83ae15..06ef33c 100644 --- a/PyroFetes/Endpoints/Quotation/DeleteQuotationEndpoint.cs +++ b/PyroFetes/Endpoints/Quotations/DeleteQuotationEndpoint.cs @@ -1,14 +1,19 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; -namespace PyroFetes.Endpoints.Quotation; +namespace PyroFetes.Endpoints.Quotations; 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() { @@ -18,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) { @@ -30,11 +33,10 @@ public class DeleteQuotationEndpoint(PyroFetesDbContext database) : Endpoint> +{ + public override void Configure() + { + Get("/api/quotations"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken 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 new file mode 100644 index 0000000..6c2355b --- /dev/null +++ b/PyroFetes/Endpoints/Quotations/GetQuotationEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Quotation.Response; +using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; + +namespace PyroFetes.Endpoints.Quotations; + +public class GetQuotationRequest +{ + public int Id { get; set; } +} + +public class GetQuotationEndpoint( + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/quotations/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetQuotationRequest req, CancellationToken ct) + { + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); + + if (quotation == null) + { + await Send.NotFoundAsync(ct); + return; + } + + 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 new file mode 100644 index 0000000..c68d1e9 --- /dev/null +++ b/PyroFetes/Endpoints/Quotations/PatchQuotationConditionsSaleEndpoint.cs @@ -0,0 +1,38 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Quotation.Request; +using PyroFetes.DTO.Quotation.Response; +using PyroFetes.DTO.QuotationProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Quotations; + +namespace PyroFetes.Endpoints.Quotations; + +public class PatchQuotationConditionsSaleEndpoint( + QuotationsRepository quotationsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/quotations/{@Id}/ConditionsSale", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchQuotationConditionsSaleDto req, CancellationToken ct) + { + Quotation? quotation = await quotationsRepository.FirstOrDefaultAsync(new GetQuotationByIdSpec(req.Id), ct); + + if (quotation == null) + { + await Send.NotFoundAsync(ct); + return; + } + + quotation.ConditionsSale = req.ConditionsSale; + await quotationsRepository.UpdateAsync(quotation, ct); + + + await Send.OkAsync(mapper.Map(quotation), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs deleted file mode 100644 index 246ad91..0000000 --- a/PyroFetes/Endpoints/SettingEndpoints/CreateSettingEndpoint.cs +++ /dev/null @@ -1,34 +0,0 @@ -using FastEndpoints; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; - -namespace PyroFetes.Endpoints.SettingEndpoints; - -public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Post("/api/setting"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct) - { - var setting = new Models.Setting() - { - ElectronicSignature = req.ElectronicSignature, - Logo = req.Logo - }; - - database.Settings.Add(setting); - await database.SaveChangesAsync(ct); - - GetSettingDto responseDto = new() - { - Id = setting.Id, - ElectronicSignature = setting.ElectronicSignature, - Logo = setting.Logo - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs deleted file mode 100644 index 64aa17b..0000000 --- a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingElectronicSignatureEndpoint.cs +++ /dev/null @@ -1,38 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; - -namespace PyroFetes.Endpoints.SettingEndpoints; - -public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) - { - var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (setting == null) - { - await Send.NotFoundAsync(ct); - return; - } - - setting.ElectronicSignature = req.ElectronicSignature; - await database.SaveChangesAsync(ct); - - GetSettingDto responseDto = new() - { - Id = setting.Id, - ElectronicSignature = setting.ElectronicSignature, - Logo = setting.Logo - }; - - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs b/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs deleted file mode 100644 index f62d033..0000000 --- a/PyroFetes/Endpoints/SettingEndpoints/PatchSettingLogoEndpoint.cs +++ /dev/null @@ -1,38 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.SettingDTO.Request; -using PyroFetes.DTO.SettingDTO.Response; - -namespace PyroFetes.Endpoints.SettingEndpoints; - -public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/setting/{@Id}/Logo", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) - { - var setting = await database.Settings.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (setting == null) - { - await Send.NotFoundAsync(ct); - return; - } - - setting.Logo = req.Logo; - await database.SaveChangesAsync(ct); - - GetSettingDto responseDto = new() - { - Id = setting.Id, - ElectronicSignature = setting.ElectronicSignature, - Logo = setting.Logo - }; - - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs new file mode 100644 index 0000000..0a6f1dd --- /dev/null +++ b/PyroFetes/Endpoints/Settings/CreateSettingEndpoint.cs @@ -0,0 +1,31 @@ +using FastEndpoints; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.Settings; + +public class CreateSettingEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/setting"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateSettingDto req, CancellationToken ct) + { + Setting setting = new Setting() + { + ElectronicSignature = req.ElectronicSignature, + Logo = req.Logo + }; + + await settingsRepository.AddAsync(setting, ct); + + await Send.OkAsync(mapper.Map(setting), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs b/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs similarity index 57% rename from PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs rename to PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs index f5800d1..f608259 100644 --- a/PyroFetes/Endpoints/SettingEndpoints/DeleteSettingEndpoint.cs +++ b/PyroFetes/Endpoints/Settings/DeleteSettingEndpoint.cs @@ -1,14 +1,17 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; -namespace PyroFetes.Endpoints.SettingEndpoints; +namespace PyroFetes.Endpoints.Settings; public class DeleteSettingRequest { public int Id { get; set; } } -public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteSettingEndpoint(SettingsRepository settingsRepository) : Endpoint { public override void Configure() { @@ -18,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) { @@ -26,8 +29,7 @@ public class DeleteSettingEndpoint(PyroFetesDbContext database) : Endpoint +public class GetSettingEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -19,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) { @@ -28,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 new file mode 100644 index 0000000..4e54c0e --- /dev/null +++ b/PyroFetes/Endpoints/Settings/PatchSettingElectronicSignatureEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; + +namespace PyroFetes.Endpoints.Settings; + +public class PatchSettingElectronicSignatureEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/setting/{@Id}/ElectronicSignature", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchSettingElectronicSignatureDto req, CancellationToken ct) + { + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + + if (setting == null) + { + await Send.NotFoundAsync(ct); + return; + } + + setting.ElectronicSignature = req.ElectronicSignature; + await settingsRepository.UpdateAsync(setting, 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 new file mode 100644 index 0000000..99ff25a --- /dev/null +++ b/PyroFetes/Endpoints/Settings/PatchSettingLogoEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.SettingDTO.Request; +using PyroFetes.DTO.SettingDTO.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Settings; + +namespace PyroFetes.Endpoints.Settings; + +public class PatchSettingLogoEndpoint( + SettingsRepository settingsRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/setting/{@Id}/Logo", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchSettingLogoDto req, CancellationToken ct) + { + Setting? setting = await settingsRepository.FirstOrDefaultAsync(new GetSettingByIdSpec(req.Id), ct); + + if (setting == null) + { + await Send.NotFoundAsync(ct); + return; + } + + setting.Logo = req.Logo; + await settingsRepository.UpdateAsync(setting, ct); + + await Send.OkAsync(mapper.Map(setting), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs deleted file mode 100644 index 15b9535..0000000 --- a/PyroFetes/Endpoints/Supplier/CreateSupplierEndpoint.cs +++ /dev/null @@ -1,44 +0,0 @@ -using PyroFetes.DTO.Supplier.Request; -using PyroFetes.DTO.Supplier.Response; -using FastEndpoints; - -namespace PyroFetes.Endpoints.Supplier; - -public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Post("/api/suppliers"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) - { - var supplier = new Models.Supplier() - { - Name = req.Name, - Email = req.Email, - Phone = req.Phone, - Address = req.Address, - City = req.City, - ZipCode = req.ZipCode, - DeliveryDelay = req.DeliveryDelay - }; - - database.Suppliers.Add(supplier); - await database.SaveChangesAsync(ct); - - GetSupplierDto responseDto = new() - { - Id = supplier.Id, - Name = supplier.Name, - Email = supplier.Email, - Phone = supplier.Phone, - Address = supplier.Address, - City = supplier.City, - ZipCode = supplier.ZipCode, - DeliveryDelay = supplier.DeliveryDelay - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs deleted file mode 100644 index 980b013..0000000 --- a/PyroFetes/Endpoints/Supplier/GetAllSuppliersEndpoint.cs +++ /dev/null @@ -1,33 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.PurchaseProduct.Response; -using PyroFetes.DTO.Supplier.Response; - -namespace PyroFetes.Endpoints.Supplier; - -public class GetAllSuppliersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> -{ - public override void Configure() - { - Get("/api/suppliers"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CancellationToken ct) - { - var 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs b/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs deleted file mode 100644 index 8e1af73..0000000 --- a/PyroFetes/Endpoints/Supplier/GetSupplierEndpoint.cs +++ /dev/null @@ -1,44 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Supplier.Response; - -namespace PyroFetes.Endpoints.Supplier; - -public class GetSupplierRequest -{ - public int Id { get; set; } -} - -public class GetSupplierEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/suppliers/{@Id}", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) - { - var supplier = await database.Suppliers - .SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (supplier == null) - { - await Send.NotFoundAsync(ct); - return; - } - - GetSupplierDto responseDto = new() - { - Id = supplier.Id, - Name = supplier.Name, - Email = supplier.Email, - Phone = supplier.Phone, - Address = supplier.Address, - City = supplier.City, - ZipCode = supplier.ZipCode, - DeliveryDelay = supplier.DeliveryDelay - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs deleted file mode 100644 index 713dece..0000000 --- a/PyroFetes/Endpoints/Supplier/PatchSupplierDeleveryDelayEndpoint.cs +++ /dev/null @@ -1,37 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.Supplier.Request; -using PyroFetes.DTO.Supplier.Response; - -namespace PyroFetes.Endpoints.Supplier; - -public class PatchSupplierDeleveryDelayEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) - { - var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (supplier == null) - { - await Send.NotFoundAsync(ct); - return; - } - - supplier.DeliveryDelay = req.DeliveryDelay; - await database.SaveChangesAsync(ct); - - GetSupplierDto responseDto = new() - { - Id = supplier.Id, - DeliveryDelay = supplier.DeliveryDelay, - }; - - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs new file mode 100644 index 0000000..19f674c --- /dev/null +++ b/PyroFetes/Endpoints/Suppliers/CreateSupplierEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using PyroFetes.DTO.Supplier.Request; +using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; + +namespace PyroFetes.Endpoints.Suppliers; + +public class CreateSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Post("/api/suppliers"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct) + { + Supplier? supplier = new Supplier() + { + Name = req.Name, + Email = req.Email, + Phone = req.Phone, + Address = req.Address, + City = req.City, + ZipCode = req.ZipCode, + DeliveryDelay = req.DeliveryDelay + }; + + await suppliersRepository.AddAsync(supplier, ct); + + await Send.OkAsync(mapper.Map(supplier), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs similarity index 56% rename from PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs index 5d87ed8..4aaef71 100644 --- a/PyroFetes/Endpoints/Supplier/DeleteSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/DeleteSupplierEndpoint.cs @@ -1,14 +1,17 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; public class DeleteSupplierRequest { public int Id { get; set; } } -public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteSupplierEndpoint(SuppliersRepository suppliersRepository) : Endpoint { public override void Configure() { @@ -18,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) { @@ -26,8 +29,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint> +{ + public override void Configure() + { + Get("/api/suppliers"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken 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 new file mode 100644 index 0000000..7c6377a --- /dev/null +++ b/PyroFetes/Endpoints/Suppliers/GetSupplierEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; + +namespace PyroFetes.Endpoints.Suppliers; + +public class GetSupplierRequest +{ + public int Id { get; set; } +} + +public class GetSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/suppliers/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct) + { + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await Send.OkAsync(mapper.Map(supplier), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs new file mode 100644 index 0000000..f4ece04 --- /dev/null +++ b/PyroFetes/Endpoints/Suppliers/PatchSupplierDeleveryDelayEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.Supplier.Request; +using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; + +namespace PyroFetes.Endpoints.Suppliers; + +public class PatchSupplierDeleveryDelayEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchSupplierDeliveryDelayDto req, CancellationToken ct) + { + Supplier? supplier = await suppliersRepository.FirstOrDefaultAsync(new GetSupplierByIdSpec(req.Id), ct); + + if (supplier == null) + { + await Send.NotFoundAsync(ct); + return; + } + + supplier.DeliveryDelay = req.DeliveryDelay; + await suppliersRepository.UpdateAsync(supplier, ct); + + await Send.OkAsync(mapper.Map(supplier), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs similarity index 52% rename from PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs rename to PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs index 1525921..0ef1516 100644 --- a/PyroFetes/Endpoints/Supplier/UpdateSupplierEndpoint.cs +++ b/PyroFetes/Endpoints/Suppliers/UpdateSupplierEndpoint.cs @@ -2,10 +2,15 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.Supplier.Request; using PyroFetes.DTO.Supplier.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Suppliers; -namespace PyroFetes.Endpoints.Supplier; +namespace PyroFetes.Endpoints.Suppliers; -public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateSupplierEndpoint( + SuppliersRepository suppliersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -15,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) { @@ -30,20 +35,9 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint(supplier), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs b/PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs deleted file mode 100644 index a9c4df5..0000000 --- a/PyroFetes/Endpoints/User/GetAllUsersEndpoint.cs +++ /dev/null @@ -1,31 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.User.Response; - -namespace PyroFetes.Endpoints.User; - -public class GetAllUsersEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest> -{ - public override void Configure() - { - Get("/api/users"); - AllowAnonymous(); - } - - public override async Task HandleAsync(CancellationToken ct) - { - var 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/GetUserEndpoint.cs b/PyroFetes/Endpoints/User/GetUserEndpoint.cs deleted file mode 100644 index 491d99f..0000000 --- a/PyroFetes/Endpoints/User/GetUserEndpoint.cs +++ /dev/null @@ -1,43 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.User.Response; - -namespace PyroFetes.Endpoints.User; - -public class GetUserRequest -{ - public int Id { get; set; } -} - -public class GetUserEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Get("/api/users/{@Id}", x => new {x.Id}); - AllowAnonymous(); - } - - public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) - { - var user = await database.Users - .SingleOrDefaultAsync(x => x.Id == req.Id, ct); - - if (user == null) - { - await Send.NotFoundAsync(ct); - return; - } - - GetUserDto responseDto = new() - { - Id = user.Id, - Name = user.Name, - Password = user.Password, - Salt = user.Salt, - Email = user.Email, - Fonction = user.Fonction - }; - - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs b/PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs deleted file mode 100644 index 4049b89..0000000 --- a/PyroFetes/Endpoints/User/PatchUserPasswordEndpoint.cs +++ /dev/null @@ -1,39 +0,0 @@ -using FastEndpoints; -using Microsoft.EntityFrameworkCore; -using PyroFetes.DTO.User.Request; -using PyroFetes.DTO.User.Response; - -namespace PyroFetes.Endpoints.User; - -public class PatchUserPasswordEndpoint(PyroFetesDbContext database) : Endpoint -{ - public override void Configure() - { - Patch("/api/users/{@Id}/Password", x => new { x.Id }); - AllowAnonymous(); - } - - public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct) - { - var user = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct); - if (user == null) - { - await Send.NotFoundAsync(ct); - return; - } - - user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt); - await database.SaveChangesAsync(ct); - - GetUserDto responseDto = new() - { - Id = user.Id, - Name = user.Name, - Password = user.Password, - Salt = user.Salt, - Email = user.Email, - Fonction = user.Fonction - }; - await Send.OkAsync(responseDto, ct); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/ConnectUserEndpoint.cs b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs similarity index 75% rename from PyroFetes/Endpoints/User/ConnectUserEndpoint.cs rename to PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs index b84c932..916f41e 100644 --- a/PyroFetes/Endpoints/User/ConnectUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/ConnectUserEndpoint.cs @@ -3,10 +3,13 @@ using FastEndpoints.Security; 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.User; +namespace PyroFetes.Endpoints.Users; -public class ConnectUserEndpoint(PyroFetesDbContext database) : Endpoint +public class ConnectUserEndpoint(UsersRepository usersRepository) : Endpoint { public override void Configure() { @@ -16,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) { @@ -26,7 +29,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 54% rename from PyroFetes/Endpoints/User/CreateUserEndpoint.cs rename to PyroFetes/Endpoints/Users/CreateUserEndpoint.cs index 466cb8b..1c2d261 100644 --- a/PyroFetes/Endpoints/User/CreateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/CreateUserEndpoint.cs @@ -2,10 +2,14 @@ using PasswordGenerator; using PyroFetes.DTO.User.Request; using PyroFetes.DTO.User.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; -public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint +public class CreateUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -17,7 +21,7 @@ public class CreateUserEndpoint(PyroFetesDbContext database) : Endpoint(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/DeleteUserEndpoint.cs b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs similarity index 58% rename from PyroFetes/Endpoints/User/DeleteUserEndpoint.cs rename to PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs index 1e07daa..d6df7d3 100644 --- a/PyroFetes/Endpoints/User/DeleteUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/DeleteUserEndpoint.cs @@ -1,14 +1,17 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; -namespace PyroFetes.Endpoints.User; +namespace PyroFetes.Endpoints.Users; public class DeleteUserRequest { public int Id { get; set; } } -public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint +public class DeleteUserEndpoint(UsersRepository usersRepository) : Endpoint { public override void Configure() { @@ -18,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) { @@ -26,8 +29,7 @@ public class DeleteUserEndpoint(PyroFetesDbContext database) : Endpoint> +{ + public override void Configure() + { + Get("/api/users"); + AllowAnonymous(); + } + + public override async Task HandleAsync(CancellationToken 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 new file mode 100644 index 0000000..222079d --- /dev/null +++ b/PyroFetes/Endpoints/Users/GetUserEndpoint.cs @@ -0,0 +1,37 @@ +using FastEndpoints; +using Microsoft.EntityFrameworkCore; +using PyroFetes.DTO.User.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.Users; + +namespace PyroFetes.Endpoints.Users; + +public class GetUserRequest +{ + public int Id { get; set; } +} + +public class GetUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Get("/api/users/{@Id}", x => new {x.Id}); + AllowAnonymous(); + } + + public override async Task HandleAsync(GetUserRequest req, CancellationToken ct) + { + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); + + if (user == null) + { + await Send.NotFoundAsync(ct); + return; + } + + await Send.OkAsync(mapper.Map(user), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs new file mode 100644 index 0000000..6f7491e --- /dev/null +++ b/PyroFetes/Endpoints/Users/PatchUserPasswordEndpoint.cs @@ -0,0 +1,36 @@ +using FastEndpoints; +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( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint +{ + public override void Configure() + { + Patch("/api/users/{@Id}/Password", x => new { x.Id }); + AllowAnonymous(); + } + + public override async Task HandleAsync(PatchUserPasswordDto req, CancellationToken ct) + { + User? user = await usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); + + if (user == null) + { + await Send.NotFoundAsync(ct); + return; + } + + user.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + user.Salt); + await usersRepository.UpdateAsync(user, ct); + + await Send.OkAsync(mapper.Map(user), ct); + } +} \ No newline at end of file diff --git a/PyroFetes/Endpoints/User/UpdateUserEndpoint.cs b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs similarity index 60% rename from PyroFetes/Endpoints/User/UpdateUserEndpoint.cs rename to PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs index b3adb8c..cf5f8d6 100644 --- a/PyroFetes/Endpoints/User/UpdateUserEndpoint.cs +++ b/PyroFetes/Endpoints/Users/UpdateUserEndpoint.cs @@ -3,10 +3,15 @@ using Microsoft.EntityFrameworkCore; 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.User; +namespace PyroFetes.Endpoints.Users; -public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint +public class UpdateUserEndpoint( + UsersRepository usersRepository, + AutoMapper.IMapper mapper) : Endpoint { public override void Configure() { @@ -16,8 +21,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 usersRepository.FirstOrDefaultAsync(new GetUserByIdSpec(req.Id), ct); + User? ckeckName = await usersRepository.FirstOrDefaultAsync(new GetUserByNameSpec(req.Name!), ct); if (user == null) { @@ -38,18 +43,9 @@ public class UpdateUserEndpoint(PyroFetesDbContext database) : Endpoint(user), ct); } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs similarity index 55% rename from PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs rename to PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs index 0005391..2a5c8a8 100644 --- a/PyroFetes/Endpoints/WareHouseProduct/GetTotalQuantityEndpoint.cs +++ b/PyroFetes/Endpoints/WareHouseProducts/GetTotalQuantityEndpoint.cs @@ -1,15 +1,19 @@ using FastEndpoints; using Microsoft.EntityFrameworkCore; using PyroFetes.DTO.WareHouseProduct.Response; +using PyroFetes.Models; +using PyroFetes.Repositories; +using PyroFetes.Specifications.WarehouseProducts; -namespace PyroFetes.Endpoints.WareHouseProduct; +namespace PyroFetes.Endpoints.WareHouseProducts; public class GetTotalQuantityRequest { public int ProductId { get; set; } } -public class GetTotalQuantityEndpoint(PyroFetesDbContext database) : Endpoint +public class GetTotalQuantityEndpoint( + WarehouseProductsRepository warehouseProductsRepository) : Endpoint { public override void Configure() { @@ -19,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) { @@ -28,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/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); 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); + } + } +} 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/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/Program.cs b/PyroFetes/Program.cs index 2b82940..e1a719b 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); @@ -14,11 +14,37 @@ 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(); +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(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); MapperConfiguration mappingConfig = new(mc => { @@ -35,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 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/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/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/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 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/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/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/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/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/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/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/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/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 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/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 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..37424e9 --- /dev/null +++ b/PyroFetes/Specifications/Quotations/GetQuotationByIdSpec.cs @@ -0,0 +1,14 @@ +using Ardalis.Specification; +using PyroFetes.Models; + +namespace PyroFetes.Specifications.Quotations; + +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 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 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 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 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