Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
Cristiano
2025-11-13 14:44:46 +01:00
25 changed files with 613 additions and 16 deletions

View File

@@ -4,7 +4,7 @@ public class CreatePriceDto
{
public decimal SellingPrice { get; set; }
public int SupplierId { get; set; }
public int? SupplierId { get; set; }
public string? SupplierName { get; set; }
public string? SupplierEmail { get; set; }
public string? SupplierPhone { get; set; }
@@ -13,8 +13,8 @@ public class CreatePriceDto
public string? SupplierCity { get; set; }
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; }
public int ProductReferences { get; set; }
public int? ProductId { get; set; }
public string? ProductReferences { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }

View File

@@ -2,6 +2,7 @@
public class PatchPriceSellingPriceDto
{
public int Id { get; set; }
public int ProductId { get; set; }
public int SupplierId { get; set; }
public decimal SellingPrice { get; set; }
}

View File

@@ -15,7 +15,7 @@ public class UpdatePriceDto
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; }
public int ProductReferences { get; set; }
public string? ProductReferences { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }

View File

@@ -15,7 +15,7 @@ public class GetPriceDto
public int SupplierDeliveryDelay { get; set; }
public int ProductId { get; set; }
public int ProductReferences { get; set; }
public string? ProductReferences { get; set; }
public string? ProductName { get; set; }
public decimal ProductDuration {get; set;}
public decimal ProductCaliber { get; set; }

View File

@@ -2,7 +2,7 @@ namespace PyroFetes.DTO.Product.Request;
public class CreateProductDto
{
public int References { get; set; }
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }

View File

@@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Request;
public class UpdateProductDto
{
public int Id { get; set; }
public int References { get; set; }
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }

View File

@@ -3,7 +3,7 @@ namespace PyroFetes.DTO.Product.Response;
public class GetProductDto
{
public int Id { get; set; }
public int References { get; set; }
public string? References { get; set; }
public string? Name { get; set; }
public decimal Duration {get; set;}
public decimal Caliber { get; set; }

View File

@@ -0,0 +1,104 @@
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<CreatePriceDto, GetPriceDto>
{
public override void Configure()
{
Post("/api/prices");
AllowAnonymous();
}
public override async Task HandleAsync(CreatePriceDto req, CancellationToken ct)
{
// Gestion du fournisseur
var supplier = await database.Suppliers.FirstOrDefaultAsync(s => s.Id == req.SupplierId, ct);
if (supplier == null)
{
supplier = new Models.Supplier()
{
Name = req.SupplierName,
Email = req.SupplierEmail,
Phone = req.SupplierPhone,
Address = req.SupplierAddress,
City = req.SupplierCity,
ZipCode = req.SupplierZipCode,
DeliveryDelay = req.SupplierDeliveryDelay
};
database.Suppliers.Add(supplier);
await database.SaveChangesAsync(ct);
}
// Gestion du produit
var product = await database.Products.SingleOrDefaultAsync(p => p.Id == req.ProductId, ct);
if (product == null)
{
product = new Models.Product()
{
Reference = req.ProductReferences,
Name = req.ProductName,
Duration = req.ProductDuration,
Caliber = req.ProductCaliber,
ApprovalNumber = req.ProductApprovalNumber,
Weight = req.ProductWeight,
Nec = req.ProductNec,
Image = req.ProductImage,
Link = req.ProductLink,
MinimalQuantity = req.ProductMinimalQuantity
};
database.Products.Add(product);
await database.SaveChangesAsync(ct);
}
// Vérifie si le prix existe déjà pour ce fournisseur et produit
var existingPrice = await database.Prices
.SingleOrDefaultAsync(p => p.ProductId == product.Id && p.SupplierId == supplier.Id, ct);
if (existingPrice != null)
{
await Send.ConflictAsync("Le fournisseur a déjà un prix pour ce produit.", ct);
return;
}
// Création du prix
var priceAdded = new Models.Price()
{
SellingPrice = req.SellingPrice,
SupplierId = supplier.Id,
ProductId = product.Id
};
database.Prices.Add(priceAdded);
await database.SaveChangesAsync(ct);
// Création du DTO de réponse
var responseDto = new GetPriceDto()
{
SellingPrice = priceAdded.SellingPrice,
SupplierId = supplier.Id,
ProductId = product.Id,
SupplierName = supplier.Name,
SupplierEmail = supplier.Email,
SupplierPhone = supplier.Phone,
SupplierAddress = supplier.Address,
SupplierCity = supplier.City,
SupplierZipCode = supplier.ZipCode,
SupplierDeliveryDelay = supplier.DeliveryDelay,
ProductReferences = product.Reference,
ProductName = product.Name,
ProductDuration = product.Duration,
ProductCaliber = product.Caliber,
ProductApprovalNumber = product.ApprovalNumber,
ProductWeight = product.Weight,
ProductNec = product.Nec,
ProductImage = product.Image,
ProductLink = product.Link,
ProductMinimalQuantity = product.MinimalQuantity
};
await Send.OkAsync(responseDto, ct);
}
}

View File

@@ -0,0 +1,36 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.QuotationProduct;
public class DeletePriceRequest
{
public int ProductId { get; set; }
public int SupplierId { get; set; }
}
public class DeletePriceEndpoint(PyroFetesDbContext database) : Endpoint<DeletePriceRequest>
{
public override void Configure()
{
Delete("/api/prices/{@ProductId}/{@SupplierId}", x => new {x.ProductId, x.SupplierId});
AllowAnonymous();
}
public override async Task HandleAsync(DeletePriceRequest 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;
}
database.Prices.Remove(price);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,36 @@
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<PatchPriceSellingPriceDto, GetPriceDto>
{
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);
}
}

View File

@@ -0,0 +1,36 @@
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<List<GetProductDto>>
{
public override void Configure()
{
Get("/api/products");
}
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);
}
}

View File

@@ -0,0 +1,48 @@
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<GetProductRequest, GetProductDto>
{
public override void Configure()
{
Get("/api/products/{@Id}", x => new {x.Id});
}
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);
}
}

View File

@@ -0,0 +1,46 @@
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<PatchProductMinimalStockDto, GetProductDto>
{
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);
}
}

View File

@@ -0,0 +1,54 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
namespace PyroFetes.Endpoints.Product;
public class UpdateProductEndpoint(PyroFetesDbContext database) : Endpoint<UpdateProductDto, GetProductDto>
{
public override void Configure()
{
Put("/api/products/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
{
var product = await database.Products.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (product == null)
{
await Send.NotFoundAsync(ct);
return;
}
product.Reference = req.References;
product.Name = req.Name;
product.Duration = req.Duration;
product.Caliber = req.Caliber;
product.ApprovalNumber = req.ApprovalNumber;
product.Weight = req.Weight;
product.Nec = req.Nec;
product.Image = req.Image;
product.Link = req.Link;
product.MinimalQuantity = req.MinimalQuantity;
await 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);
}
}

View File

@@ -1,7 +1,8 @@
using PyroFetes.DTO.SettingDTO.Request;
using FastEndpoints;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Setting;
namespace PyroFetes.Endpoints.SettingEndpoints;
public class CreateSettingEndpoint(PyroFetesDbContext database) : Endpoint<CreateSettingDto, GetSettingDto>
{

View File

@@ -1,7 +1,7 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Setting;
namespace PyroFetes.Endpoints.SettingEndpoints;
public class DeleteSettingRequest
{

View File

@@ -2,7 +2,7 @@
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Response;
namespace PyroFetes.Endpoints.Setting;
namespace PyroFetes.Endpoints.SettingEndpoints;
public class GetSettingRequest
{

View File

@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
namespace PyroFetes.Endpoints.Setting;
namespace PyroFetes.Endpoints.SettingEndpoints;
public class PatchSettingElectronicSignatureEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingElectronicSignatureDto, GetSettingDto>
{

View File

@@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.SettingDTO.Request;
using PyroFetes.DTO.SettingDTO.Response;
namespace PyroFetes.Endpoints.Setting;
namespace PyroFetes.Endpoints.SettingEndpoints;
public class PatchSettingLogoEndpoint(PyroFetesDbContext database) : Endpoint<PatchSettingLogoDto, GetSettingDto>
{

View File

@@ -0,0 +1,43 @@
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Supplier;
public class CreateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<CreateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
Post("/api/suppliers");
}
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);
}
}

View File

@@ -0,0 +1,33 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Supplier;
public class DeleteSupplierRequest
{
public int Id { get; set; }
}
public class DeleteSupplierEndpoint(PyroFetesDbContext database) : Endpoint<DeleteSupplierRequest>
{
public override void Configure()
{
Delete("/api/suppliers/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
{
var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (supplier == null)
{
await Send.NotFoundAsync(ct);
return;
}
database.Suppliers.Remove(supplier);
await database.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}
}

View File

@@ -0,0 +1,32 @@
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<List<GetSupplierDto>>
{
public override void Configure()
{
Get("/api/suppliers");
}
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);
}
}

View File

@@ -0,0 +1,43 @@
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<GetSupplierRequest, GetSupplierDto>
{
public override void Configure()
{
Get("/api/suppliers/{@Id}", x => new {x.Id});
}
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);
}
}

View File

@@ -0,0 +1,36 @@
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<PatchSupplierDeliveryDelayDto, GetSupplierDto>
{
public override void Configure()
{
Get("/api/supplier/{@Id}/DeleveryDalay", x => new {x.Id});
}
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);
}
}

View File

@@ -0,0 +1,48 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
namespace PyroFetes.Endpoints.Supplier;
public class UpdateSupplierEndpoint(PyroFetesDbContext database) : Endpoint<UpdateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
Put("/api/suppliers/{@Id}", x => new {x.Id});
}
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
{
var supplier = await database.Suppliers.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
if (supplier == null)
{
await Send.NotFoundAsync(ct);
return;
}
supplier.Name = req.Name;
supplier.Email = req.Email;
supplier.Phone = req.Phone;
supplier.Address = req.Address;
supplier.City = req.City;
supplier.ZipCode = req.ZipCode;
supplier.DeliveryDelay = req.DeliveryDelay;
await 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);
}
}