17:17 09/10

This commit is contained in:
2025-10-09 17:17:42 +02:00
parent 1734ec0219
commit 91b4aca2fa
76 changed files with 815 additions and 388 deletions

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Brand.Request;
namespace API.DTO.Brand.Request;
public class CreateBrandDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Brand.Request;
namespace API.DTO.Brand.Request;
public class UpdateBrandDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Brand.Response;
namespace API.DTO.Brand.Response;
public class GetBrandDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Classification.Request;
namespace API.DTO.Classification.Request;
public class CreateClassificationDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Classification.Request;
namespace API.DTO.Classification.Request;
public class UpdateClassificationDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Classification.Response;
namespace API.DTO.Classification.Response;
public class GetClassificationDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Color.Request;
namespace API.DTO.Color.Request;
public class CreateColorDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Color.Request;
namespace API.DTO.Color.Request;
public class UpdateColorDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Color.Response;
namespace API.DTO.Color.Response;
public class GetColorDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Effect.Request;
namespace API.DTO.Effect.Request;
public class CreateEffectDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Effect.Request;
namespace API.DTO.Effect.Request;
public class UpdateEffectDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Effect.Response;
namespace API.DTO.Effect.Response;
public class GetEffectDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Material.Request;
namespace API.DTO.Material.Request;
public class CreateMaterialDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Material.Request;
namespace API.DTO.Material.Request;
public class UpdateMaterialDto
{

View File

@@ -1,4 +1,4 @@
namespace PyroFetes.DTO.Material.Response;
namespace API.DTO.Material.Response;
public class GetMaterialDto
{

View File

@@ -1,7 +1,7 @@
using PyroFetes.Models;
namespace PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Request;
namespace PyroFetes.DTO.Product.Request
{
public class CreateProductDto
{
public int References { get; set; }
@@ -14,8 +14,13 @@ public class CreateProductDto
public decimal SellingPrice { get; set; }
public string? Image { get; set; }
public string? Link { get; set; }
public int ClassificationId { get; set;}
public int ProductCategoryId { get; set; }
// Liste des fournisseurs liés au produit
public List<ProductSupplierPriceDto>? Suppliers { get; set; }
// Liste des entrepôts liés au produit
public List<CreateProductWarehouseDto>? Warehouses { get; set; }
}
}

View File

@@ -1,11 +1,11 @@
using PyroFetes.Models;
namespace PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Request;
namespace PyroFetes.DTO.Product.Request
{
public class UpdateProductDto
{
public int Id { get; set; }
public int Reference { get; set; }
public int References { get; set; }
public string? Name { get; set; }
public decimal Duration { get; set; }
public decimal Caliber { get; set; }
@@ -17,4 +17,11 @@ public class UpdateProductDto
public string? Link { get; set; }
public int ClassificationId { get; set; }
public int ProductCategoryId { get; set; }
// Liste des fournisseurs associés
public List<ProductSupplierPriceDto> Suppliers { get; set; } = new();
// Liste des entrepôts associés
public List<UpdateProductWarehouseDto> Warehouses { get; set; } = new();
}
}

View File

@@ -1,7 +1,9 @@
using PyroFetes.Models;
namespace PyroFetes.DTO.Product.Response;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
namespace PyroFetes.DTO.Product.Response
{
public class GetProductDto
{
public int Id { get; set; }
@@ -16,8 +18,12 @@ public class GetProductDto
public string? Image { get; set; }
public string? Link { get; set; }
public int ClassificationId { get; set; }
public string? ClassificationLabel { get; set; }
public int ProductCategoryId { get; set; }
public string? ProductCategoryLabel { get; set; }
// Fournisseurs liés
public List<ProductSupplierPriceDto> Suppliers { get; set; } = new();
// Entrepôts liés
public List<GetProductWarehouseDto> Warehouses { get; set; } = new();
}
}

View File

@@ -0,0 +1,10 @@
namespace PyroFetes.DTO.Product.Request
{
// DTO utilisé pour créer ou mettre à jour la relation Product <-> Supplier
public class ProductSupplierPriceDto
{
public int ProductId { get; set; } // Id du produit (pour update)
public int SupplierId { get; set; } // Id du fournisseur
public decimal SellingPrice { get; set; } // Prix de vente
}
}

View File

@@ -0,0 +1,11 @@
namespace PyroFetes.DTO.Product.Response
{
// DTO pour la lecture des fournisseurs liés à un produit
public class GetProductSupplierDto
{
public int ProductId { get; set; }
public int SupplierId { get; set; }
public string SupplierName { get; set; } = string.Empty;
public decimal SellingPrice { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
namespace PyroFetes.DTO.Product.Request
{
// DTO utilisé pour créer ou mettre à jour la relation Product <-> Warehouse
public class CreateProductWarehouseDto
{
public int WarehouseId { get; set; }
public int ProductId { get; set; }
public int Quantity { get; set; }
}
public class UpdateProductWarehouseDto
{
public int WarehouseId { get; set; }
public int ProductId { get; set; }
public int Quantity { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
namespace PyroFetes.DTO.Product.Response
{
// DTO pour la lecture des entrepôts liés à un produit
public class GetProductWarehouseDto
{
public int WarehouseId { get; set; }
public int ProductId { get; set; }
public string WarehouseName { get; set; } = string.Empty;
public int Quantity { get; set; }
}
}

View File

@@ -1,4 +1,4 @@
namespace API.DTO.Supplier.Request;
namespace PyroFetes.DTO.Supplier.Request;
public class CreateSupplierDto
{
@@ -8,4 +8,13 @@ public class CreateSupplierDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
// Produits que ce fournisseur fournit
public List<SupplierProductPriceDto>? Products { get; set; }
}
public class SupplierProductPriceDto
{
public int ProductId { get; set; }
public decimal SellingPrice { get; set; }
}

View File

@@ -1,4 +1,4 @@
namespace API.DTO.Supplier.Request;
namespace PyroFetes.DTO.Supplier.Request;
public class UpdateSupplierDto
{
@@ -9,4 +9,6 @@ public class UpdateSupplierDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
public List<SupplierProductPriceDto>? Products { get; set; }
}

View File

@@ -1,4 +1,6 @@
namespace API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
namespace PyroFetes.DTO.Supplier.Response;
public class GetSupplierDto
{
@@ -9,4 +11,14 @@ public class GetSupplierDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
// Liste des produits liés avec leur prix fournisseur
public List<SupplierProductPriceDto> Products { get; set; }
}
public class GetSupplierProductDto
{
public int ProductId { get; set; }
public string ProductName { get; set; } = string.Empty;
public decimal SellingPrice { get; set; }
}

View File

@@ -9,4 +9,13 @@ public class CreateWarehouseDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
// Liste des produits à stocker dans cet entrepôt
public List<CreateWarehouseProductDto>? Products { get; set; }
}
public class CreateWarehouseProductDto
{
public int ProductId { get; set; }
public int Quantity { get; set; }
}

View File

@@ -10,4 +10,12 @@ public class UpdateWarehouseDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
public List<UpdateWarehouseProductDto>? Products { get; set; }
}
public class UpdateWarehouseProductDto
{
public int ProductId { get; set; }
public int Quantity { get; set; }
}

View File

@@ -10,4 +10,13 @@ public class GetWarehouseDto
public string Adress { get; set; }
public int ZipCode { get; set; }
public string City { get; set; }
public List<WarehouseProductDto>? Products { get; set; }
}
public class WarehouseProductDto
{
public int ProductId { get; set; }
public string? ProductName { get; set; }
public int Quantity { get; set; }
}

View File

@@ -1,5 +1,5 @@
using PyroFetes.DTO.Brand.Request;
using PyroFetes.DTO.Brand.Response;
using API.DTO.Brand.Request;
using API.DTO.Brand.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Brand;

View File

@@ -1,4 +1,4 @@
using PyroFetes.DTO.Brand.Response;
using API.DTO.Brand.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,4 +1,4 @@
using PyroFetes.DTO.Brand.Response;
using API.DTO.Brand.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,5 +1,5 @@
using PyroFetes.DTO.Brand.Request;
using PyroFetes.DTO.Brand.Response;
using API.DTO.Brand.Request;
using API.DTO.Brand.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Brand;
@@ -8,7 +8,7 @@ public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Post("/api/brands");
Put("/api/brands");
AllowAnonymous();
}

View File

@@ -1,5 +1,5 @@
using PyroFetes.DTO.Classification.Request;
using PyroFetes.DTO.Classification.Response;
using API.DTO.Classification.Request;
using API.DTO.Classification.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Classification;

View File

@@ -1,4 +1,4 @@
using PyroFetes.DTO.Classification.Response;
using API.DTO.Classification.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,4 +1,4 @@
using PyroFetes.DTO.Classification.Response;
using API.DTO.Classification.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;

View File

@@ -1,5 +1,5 @@
using PyroFetes.DTO.Classification.Request;
using PyroFetes.DTO.Classification.Response;
using API.DTO.Classification.Request;
using API.DTO.Classification.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Classification;
@@ -8,7 +8,7 @@ public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Post("/api/classifications");
Put("/api/classifications");
AllowAnonymous();
}

View File

@@ -1,14 +1,14 @@
using PyroFetes.DTO.Color.Request;
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Request;
using API.DTO.Color.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Color;
public class CreateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
public class CreateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateColorDto, GetColorDto>
{
public override void Configure()
{
Post("/api/color/create");
Post("/color/create");
AllowAnonymous();
}
@@ -19,8 +19,8 @@ public class CreateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Cre
Label = req.Label,
};
appDbContext.Colors.Add(color);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Colors.Add(color);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Added Color");
GetColorDto responseDto = new()

View File

@@ -8,17 +8,17 @@ public class DeleteColorRequest
public int Id { get; set; }
}
public class DeleteColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteColorRequest>
public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteColorRequest>
{
public override void Configure()
{
Delete("/api/colors/{@id}", x => new { x.Id });
Delete("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
{
Models.Color? colorToDelete = await appDbContext
Models.Color? colorToDelete = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -29,8 +29,8 @@ public class DeleteColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Del
return;
}
appDbContext.Colors.Remove(colorToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Colors.Remove(colorToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,20 +1,20 @@
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
public class GetAllColorsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetColorDto>>
{
public override void Configure()
{
Get("/api/colors");
Get("/colors");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetColorDto> responseDto = await appDbContext.Colors
List<GetColorDto> responseDto = await pyrofetesdbcontext.Colors
.Select(a => new GetColorDto
{
Id = a.Id,

View File

@@ -1,6 +1,5 @@
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
@@ -10,23 +9,23 @@ public class GetColorRequest
public int Id { get; set; }
}
public class GetColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<GetColorRequest, GetColorDto>
public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetColorRequest, GetColorDto>
{
public override void Configure()
{
Get("/api/colors/{@id}", x => new { x.Id});
Get("/colors/{@id}", x => new { x.Id});
AllowAnonymous();
}
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
{
Models.Color? color = await appDbContext
Models.Color? color = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (color == null)
{
Console.WriteLine($"Aucune couleur avec l'ID {req.Id} trouvé.");
Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}

View File

@@ -1,34 +1,33 @@
using PyroFetes.DTO.Color.Request;
using PyroFetes.DTO.Color.Response;
using API.DTO.Color.Request;
using API.DTO.Color.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Color;
public class UpdateColorEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateColorDto, GetColorDto>
public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateColorDto, GetColorDto>
{
public override void Configure()
{
Put("/api/colors/{@id}", x => new { x.Id });
Put("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
{
Models.Color? colorToEdit = await appDbContext
Models.Color? colorToEdit = await pyrofetesdbcontext
.Colors
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (colorToEdit == null)
{
Console.WriteLine($"Aucune couleur avec l'id {req.Id} trouvé.");
Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
colorToEdit.Label = req.Label;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetColorDto responseDto = new()
{

View File

@@ -1,14 +1,14 @@
using PyroFetes.DTO.Effect.Request;
using PyroFetes.DTO.Effect.Response;
using API.DTO.Effect.Request;
using API.DTO.Effect.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Effect;
public class CreateEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateEffectDto, GetEffectDto>
public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateEffectDto, GetEffectDto>
{
public override void Configure()
{
Post("/api/effect/create");
Post("/effect/create");
AllowAnonymous();
}
@@ -19,8 +19,8 @@ public class CreateEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Cr
Label = req.Label,
};
appDbContext.Effects.Add(effect);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Effects.Add(effect);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Effect added");
GetEffectDto responseDto = new()

View File

@@ -7,17 +7,17 @@ public class DeleteEffectRequest
{
public int Id { get; set; }
}
public class DeleteEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteEffectRequest>
public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteEffectRequest>
{
public override void Configure()
{
Delete("/api/effects/{@id}", x => new { x.Id });
Delete("/effects/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
{
Models.Effect? effectToDelete = await appDbContext
Models.Effect? effectToDelete = await pyrofetesdbcontext
.Effects
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -28,8 +28,8 @@ public class DeleteEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<De
return;
}
appDbContext.Effects.Remove(effectToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Effects.Remove(effectToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,20 +1,20 @@
using PyroFetes.DTO.Effect.Response;
using API.DTO.Effect.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Effect;
public class GetAllEffectsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetEffectDto>>
public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetEffectDto>>
{
public override void Configure()
{
Get("/api/effects");
Get("/effects");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetEffectDto> responseDto = await appDbContext.Effects
List<GetEffectDto> responseDto = await pyrofetesdbcontext.Effects
.Select(a => new GetEffectDto
{
Id = a.Id,

View File

@@ -1,6 +1,5 @@
using PyroFetes.DTO.Effect.Response;
using API.DTO.Effect.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Effect;
@@ -10,23 +9,23 @@ public class GetEffectRequest
public int Id { get; set; }
}
public class GetEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<GetEffectRequest, GetEffectDto>
public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetEffectRequest, GetEffectDto>
{
public override void Configure()
{
Get("/api/effect/{@id}", x => new { x.Id });
Get("/effect/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
{
Models.Effect? effect = await appDbContext
Models.Effect? effect = await pyrofetesdbcontext
.Effects
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (effect == null)
{
Console.WriteLine($"Aucun effet avec l'ID {req.Id} trouvé.");
Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}

View File

@@ -1,34 +1,33 @@
using PyroFetes.DTO.Effect.Request;
using PyroFetes.DTO.Effect.Response;
using API.DTO.Effect.Request;
using API.DTO.Effect.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Effect;
public class UpdateEffectEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateEffectDto, GetEffectDto>
public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateEffectDto, GetEffectDto>
{
public override void Configure()
{
Put("/api/effect/{@id}", x => new { x.Id });
Put("/effect/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
{
Models.Effect? effectToEdit = await appDbContext
Models.Effect? effectToEdit = await pyrofetesdbcontext
.Effects
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (effectToEdit == null)
{
Console.WriteLine($"Aucun effet avec l'id {req.Id} trouvé.");
Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
effectToEdit.Label = req.Label;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetEffectDto responseDto = new()
{

View File

@@ -1,33 +1,34 @@
using PyroFetes.DTO.Material.Request;
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
namespace PyroFetes.Endpoints.Material;
public class CreateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Post("/api/material/create");
Post("/material/create");
AllowAnonymous();
}
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
{
Models.Material material = new()
Models.Material quantity = new()
{
Label = req.Label,
Name = req.Label,
Quantity = req.Quantity,
WarehouseId = req.WarehouseId,
};
appDbContext.Materials.Add(material);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Materials.Add(quantity);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Material added");
GetMaterialDto responseDto = new()
{
Id = material.Id,
WarehouseId = material.WarehouseId,
Id = quantity.Id,
WarehouseId = quantity.WarehouseId,
Label = req.Label,
};

View File

@@ -6,17 +6,17 @@ public class DeleteMaterialRequest
{
public int Id { get; set; }
}
public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<DeleteMaterialRequest>
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
{
public override void Configure()
{
Delete("/api/materials/{@id}", x => new { x.Id });
Delete("/materials/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
{
Models.Material? materialToDelete = await appDbContext
Models.Material? materialToDelete = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
@@ -27,8 +27,8 @@ public class DeleteMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<
return;
}
appDbContext.Materials.Remove(materialToDelete);
await appDbContext.SaveChangesAsync(ct);
pyrofetesdbcontext.Materials.Remove(materialToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
await Send.NoContentAsync(ct);
}

View File

@@ -1,24 +1,24 @@
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class GetAllMaterialsEndpoint(PyroFetesDbContext appDbContext) : EndpointWithoutRequest<List<GetMaterialDto>>
public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMaterialDto>>
{
public override void Configure()
{
Get("/api/material");
Get("/material");
AllowAnonymous();
}
public override async Task HandleAsync(CancellationToken ct)
{
List<GetMaterialDto> responseDto = await appDbContext.Materials
List<GetMaterialDto> responseDto = await pyrofetesdbcontext.Materials
.Select(a => new GetMaterialDto
{
Id = a.Id,
Label = a.Label,
Label = a.Name,
Quantity = a.Quantity,
WarehouseId = a.WarehouseId,
}

View File

@@ -1,6 +1,5 @@
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
@@ -10,17 +9,17 @@ public class GetMaterialRequest
public int Id { get; set; }
}
public class GetMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<GetMaterialRequest, GetMaterialDto>
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
{
public override void Configure()
{
Get("/api/material/{@id}", x => new { x.Id });
Get("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
{
Models.Material? material = await appDbContext
Models.Material? material = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
@@ -34,7 +33,7 @@ public class GetMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<Get
GetMaterialDto responseDto = new()
{
Id = material.Id,
Label = material.Label,
Label = material.Name,
WarehouseId = material.WarehouseId,
};
await Send.OkAsync(responseDto, ct);

View File

@@ -1,35 +1,34 @@
using PyroFetes.DTO.Material.Request;
using PyroFetes.DTO.Material.Response;
using API.DTO.Material.Request;
using API.DTO.Material.Response;
using FastEndpoints;
using Microsoft.AspNetCore.Server.Kestrel;
using Microsoft.EntityFrameworkCore;
namespace PyroFetes.Endpoints.Material;
public class UpdateMaterialEndpoint(PyroFetesDbContext appDbContext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
{
public override void Configure()
{
Put("/api/material/{@id}", x => new { x.Id });
Put("/material/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
{
Models.Material? materialToEdit = await appDbContext
Models.Material? materialToEdit = await pyrofetesdbcontext
.Materials
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
if (materialToEdit == null)
{
Console.WriteLine($"Aucun matériel avec l'id {req.Id} trouvé.");
Console.WriteLine("Aucun matériel avec l'id {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
materialToEdit.Label = req.Label;
materialToEdit.Name = req.Label;
materialToEdit.WarehouseId = req.WarehouseId;
await appDbContext.SaveChangesAsync(ct);
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetMaterialDto responseDto = new()
{

View File

@@ -8,7 +8,7 @@ public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Post("/api/movements");
Put("/api/movements");
AllowAnonymous();
}

View File

@@ -1,10 +1,15 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateProductDto, GetProductDto>
public class CreateProductEndpoint(PyroFetesDbContext db)
: Endpoint<CreateProductDto, GetProductDto>
{
public override void Configure()
{
@@ -14,7 +19,7 @@ public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
public override async Task HandleAsync(CreateProductDto req, CancellationToken ct)
{
Models.Product product = new ()
var product = new Models.Product
{
References = req.References,
Name = req.Name!,
@@ -30,12 +35,47 @@ public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
ClassificationId = req.ClassificationId
};
pyrofetesdbcontext.Products.Add(product);
await pyrofetesdbcontext.SaveChangesAsync(ct);
db.Products.Add(product);
await db.SaveChangesAsync(ct);
Console.WriteLine("Product créé avec succès !");
// Ajout des fournisseurs liés
if (req.Suppliers is not null && req.Suppliers.Any())
{
foreach (var s in req.Suppliers)
{
var price = new Price
{
ProductId = product.Id,
SupplierId = s.SupplierId,
SellingPrice = s.SellingPrice
};
db.Prices.Add(price);
}
await db.SaveChangesAsync(ct);
}
GetProductDto responseDto = new ()
// Ajout des entrepôts liés
if (req.Warehouses is not null && req.Warehouses.Any())
{
foreach (var w in req.Warehouses)
{
var exists = await db.Warehouses.AnyAsync(x => x.Id == w.WarehouseId, ct);
if (!exists)
continue; // sécurité : on ignore les warehouses inexistants
var warehouseProduct = new WarehouseProduct
{
ProductId = product.Id,
WarehouseId = w.WarehouseId,
Quantity = w.Quantity
};
db.WarehouseProducts.Add(warehouseProduct);
}
await db.SaveChangesAsync(ct);
}
// Construction de la réponse
var response = new GetProductDto
{
Id = product.Id,
Reference = req.References,
@@ -49,9 +89,20 @@ public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
Image = req.Image,
Link = req.Link,
ProductCategoryId = req.ProductCategoryId,
ClassificationId = req.ClassificationId
ClassificationId = req.ClassificationId,
Suppliers = req.Suppliers?.Select(s => new ProductSupplierPriceDto
{
SupplierId = s.SupplierId,
SellingPrice = s.SellingPrice
}).ToList() ?? new(),
Warehouses = req.Warehouses?.Select(w => new GetProductWarehouseDto
{
WarehouseId = w.WarehouseId,
Quantity = w.Quantity,
WarehouseName = db.Warehouses.FirstOrDefault(x => x.Id == w.WarehouseId)?.Name ?? string.Empty
}).ToList() ?? new()
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,5 +1,6 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
@@ -8,7 +9,7 @@ public class DeleteProductRequest
public int Id { get; set; }
}
public class DeleteProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteProductRequest>
public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint<DeleteProductRequest>
{
public override void Configure()
{
@@ -18,19 +19,40 @@ public class DeleteProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct)
{
Models.Product? productToDelete = await pyrofetesdbcontext
.Products
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
// Récupérer le produit
var productToDelete = await db.Products
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
if (productToDelete == null)
if (productToDelete is null)
{
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
pyrofetesdbcontext.Products.Remove(productToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
// Supprimer les liaisons Price
var relatedPrices = await db.Prices
.Where(p => p.ProductId == req.Id)
.ToListAsync(ct);
if (relatedPrices.Any())
{
db.Prices.RemoveRange(relatedPrices);
}
// Supprimer les liaisons WarehouseProduct
var relatedWarehouseProducts = await db.WarehouseProducts
.Where(wp => wp.ProductId == req.Id)
.ToListAsync(ct);
if (relatedWarehouseProducts.Any())
{
db.WarehouseProducts.RemoveRange(relatedWarehouseProducts);
}
// Supprimer le produit
db.Products.Remove(productToDelete);
await db.SaveChangesAsync(ct);
Console.WriteLine($"Produit {req.Id}, ses prix et ses entrepôts liés ont été supprimés avec succès.");
await Send.NoContentAsync(ct);
}

View File

@@ -1,10 +1,15 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductDto>>
public class GetAllProductsEndpoint(PyroFetesDbContext db)
: EndpointWithoutRequest<List<GetProductDto>>
{
public override void Configure()
{
@@ -14,8 +19,14 @@ public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
public override async Task HandleAsync(CancellationToken ct)
{
List<GetProductDto> responseDto = await pyrofetesdbcontext.Products
.Select(p => new GetProductDto()
// Inclure toutes les relations nécessaires : Prices + WarehouseProducts + Warehouse
var products = await db.Products
.Include(p => p.Prices)
.Include(p => p.WarehouseProducts)
.ThenInclude(wp => wp.Warehouse)
.ToListAsync(ct);
var responseDto = products.Select(p => new GetProductDto
{
Id = p.Id,
Reference = p.References,
@@ -29,11 +40,23 @@ public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
Image = p.Image,
Link = p.Link,
ClassificationId = p.ClassificationId,
ClassificationLabel = p.Classification!.Label,
ProductCategoryId = p.ProductCategoryId,
ProductCategoryLabel = p.ProductCategory!.Label,
}
).ToListAsync(ct);
// Liste des fournisseurs liés via Price
Suppliers = p.Prices.Select(pr => new ProductSupplierPriceDto
{
SupplierId = pr.SupplierId,
SellingPrice = pr.SellingPrice
}).ToList(),
// Liste des entrepôts via WarehouseProduct
Warehouses = p.WarehouseProducts.Select(wp => new GetProductWarehouseDto
{
WarehouseId = wp.WarehouseId,
WarehouseName = wp.Warehouse?.Name ?? string.Empty,
Quantity = wp.Quantity
}).ToList()
}).ToList();
await Send.OkAsync(responseDto, ct);
}

View File

@@ -1,6 +1,10 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
@@ -9,20 +13,23 @@ public class GetProductRequest
public int Id { get; set; }
}
public class GetProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetProductRequest, GetProductDto>
public class GetProductEndpoint(PyroFetesDbContext db)
: Endpoint<GetProductRequest, GetProductDto>
{
public override void Configure()
{
Get("/api/product/{@id}", x => new { x.Id });
Get("/api/products/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
{
Models.Product? product = await pyrofetesdbcontext
.Products.Include(product => product.Classification).Include(product => product.ProductCategory)
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
// Inclure toutes les relations : Prices + WarehouseProducts + Warehouse
var product = await db.Products
.Include(p => p.Prices)
.Include(p => p.WarehouseProducts)
.ThenInclude(wp => wp.Warehouse)
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
if (product == null)
{
@@ -31,7 +38,7 @@ public class GetProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint
return;
}
GetProductDto responseDto = new()
var responseDto = new GetProductDto
{
Id = product.Id,
Reference = product.References,
@@ -45,9 +52,22 @@ public class GetProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint
Image = product.Image,
Link = product.Link,
ClassificationId = product.ClassificationId,
ClassificationLabel = product.Classification!.Label,
ProductCategoryId = product.ProductCategoryId,
ProductCategoryLabel = product.ProductCategory!.Label,
// Fournisseurs liés via Price
Suppliers = product.Prices.Select(pr => new ProductSupplierPriceDto
{
SupplierId = pr.SupplierId,
SellingPrice = pr.SellingPrice
}).ToList(),
// Entrepôts liés via WarehouseProduct
Warehouses = product.WarehouseProducts.Select(wp => new GetProductWarehouseDto
{
WarehouseId = wp.WarehouseId,
WarehouseName = wp.Warehouse?.Name ?? string.Empty,
Quantity = wp.Quantity
}).ToList()
};
await Send.OkAsync(responseDto, ct);

View File

@@ -1,47 +1,90 @@
using FastEndpoints;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.DTO.Product.Request;
using PyroFetes.DTO.Product.Response;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Product;
public class UpdateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<UpdateProductDto, GetProductDto>
// Endpoint permettant de mettre à jour un produit existant
public class UpdateProductEndpoint(PyroFetesDbContext db)
: Endpoint<UpdateProductDto, GetProductDto>
{
public override void Configure()
{
// Route HTTP PUT avec un paramètre d'identifiant dans l'URL
Put("/api/products/{@id}", x => new { x.Id });
// Autorise les requêtes anonymes (sans authentification)
AllowAnonymous();
}
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
{
Models.Product? productToEdit = await pyrofetesdbcontext
.Products
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
// Recherche du produit à mettre à jour, en incluant les relations Prices et WarehouseProducts
var product = await db.Products
.Include(p => p.Prices)
.Include(p => p.WarehouseProducts)
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
if (productToEdit == null)
// Si le produit n'existe pas, on retourne une réponse 404
if (product is null)
{
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
productToEdit.References = req.Reference;
productToEdit.Name = req.Name;
productToEdit.Duration = req.Duration;
productToEdit.Caliber = req.Caliber;
productToEdit.ApprovalNumber = req.ApprovalNumber;
productToEdit.Weight = req.Weight;
productToEdit.Nec = req.Nec;
productToEdit.SellingPrice = req.SellingPrice;
productToEdit.Image = req.Image;
productToEdit.Link = req.Link;
await pyrofetesdbcontext.SaveChangesAsync(ct);
// Mise à jour des propriétés principales du produit
product.References = 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.SellingPrice = req.SellingPrice;
product.Image = req.Image;
product.Link = req.Link;
product.ClassificationId = req.ClassificationId;
product.ProductCategoryId = req.ProductCategoryId;
GetProductDto responseDto = new()
// Mise à jour des prix fournisseurs associés
// On supprime les anciens enregistrements pour les remplacer
db.Prices.RemoveRange(product.Prices);
foreach (var s in req.Suppliers)
{
Id = req.Id,
Reference = req.Reference,
db.Prices.Add(new Price
{
ProductId = product.Id,
SupplierId = s.SupplierId,
SellingPrice = s.SellingPrice
});
}
// Mise à jour des entrepôts associés
// On supprime les anciens liens avant d'ajouter les nouveaux
db.WarehouseProducts.RemoveRange(product.WarehouseProducts);
foreach (var w in req.Warehouses)
{
db.WarehouseProducts.Add(new WarehouseProduct
{
ProductId = product.Id,
WarehouseId = w.WarehouseId,
Quantity = w.Quantity
});
}
// Sauvegarde des modifications dans la base de données
await db.SaveChangesAsync(ct);
// Construction de la réponse renvoyée au client
// On reconstruit les listes Suppliers et Warehouses au bon format de DTO
var response = new GetProductDto
{
Id = product.Id,
Reference = req.References,
Name = req.Name,
Duration = req.Duration,
Caliber = req.Caliber,
@@ -50,9 +93,27 @@ public class UpdateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpo
Nec = req.Nec,
SellingPrice = req.SellingPrice,
Image = req.Image,
Link = req.Link
Link = req.Link,
ClassificationId = req.ClassificationId,
ProductCategoryId = req.ProductCategoryId,
// Mapping des fournisseurs pour la réponse
Suppliers = req.Suppliers.Select(s => new ProductSupplierPriceDto
{
SupplierId = s.SupplierId,
SellingPrice = s.SellingPrice
}).ToList(),
// Mapping des entrepôts pour la réponse
Warehouses = req.Warehouses.Select(w => new GetProductWarehouseDto
{
WarehouseId = w.WarehouseId,
Quantity = w.Quantity,
WarehouseName = db.Warehouses.FirstOrDefault(x => x.Id == w.WarehouseId)?.Name ?? string.Empty
}).ToList()
};
await Send.OkAsync(responseDto, ct);
// Envoi de la réponse HTTP 200 avec les données du produit mis à jour
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,10 +1,13 @@
using API.DTO.Supplier.Request;
using API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Supplier;
public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateSupplierDto, GetSupplierDto>
public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
: Endpoint<CreateSupplierDto, GetSupplierDto>
{
public override void Configure()
{
@@ -14,8 +17,7 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
{
// Création d'un nouvel objet Supplier
Models.Supplier supplier = new()
var supplier = new Models.Supplier
{
Name = req.Name,
Email = req.Email,
@@ -25,14 +27,26 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
City = req.City
};
// Ajout à la base et sauvegarde
pyrofetesdbcontext.Suppliers.Add(supplier);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine("Fournisseur créé avec succès !");
// Ajout des liaisons Price si produits renseignés
if (req.Products is not null && req.Products.Any())
{
foreach (var p in req.Products)
{
var price = new Price
{
SupplierId = supplier.Id,
ProductId = p.ProductId,
SellingPrice = p.SellingPrice
};
pyrofetesdbcontext.Prices.Add(price);
}
await pyrofetesdbcontext.SaveChangesAsync(ct);
}
// Préparation de la réponse
GetSupplierDto responseDto = new()
var response = new GetSupplierDto
{
Id = supplier.Id,
Name = supplier.Name,
@@ -43,6 +57,6 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
City = supplier.City
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,5 +1,6 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Supplier;
@@ -18,19 +19,32 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
{
Models.Supplier? supplierToDelete = await pyrofetesdbcontext
var supplierToDelete = await pyrofetesdbcontext
.Suppliers
.SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct);
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
if (supplierToDelete == null)
if (supplierToDelete is null)
{
Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
// Supprimer les liaisons Price avant le fournisseur
var relatedPrices = await pyrofetesdbcontext.Prices
.Where(p => p.SupplierId == req.Id)
.ToListAsync(ct);
if (relatedPrices.Any())
{
pyrofetesdbcontext.Prices.RemoveRange(relatedPrices);
}
// Supprimer le fournisseur
pyrofetesdbcontext.Suppliers.Remove(supplierToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
Console.WriteLine($"Fournisseur {req.Id} et ses prix liés supprimés avec succès.");
await Send.NoContentAsync(ct);
}

View File

@@ -1,10 +1,13 @@
using API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Supplier;
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetSupplierDto>>
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext)
: EndpointWithoutRequest<List<GetSupplierDto>>
{
public override void Configure()
{
@@ -14,8 +17,11 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
public override async Task HandleAsync(CancellationToken ct)
{
List<GetSupplierDto> responseDto = await pyrofetesdbcontext.Suppliers
.Select(s => new GetSupplierDto
var suppliers = await pyrofetesdbcontext.Suppliers
.Include(s => s.Prices)
.ToListAsync(ct);
var responseDto = suppliers.Select(s => new GetSupplierDto
{
Id = s.Id,
Name = s.Name!,
@@ -23,9 +29,15 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
PhoneNumber = s.Phone!,
Adress = s.Address!,
ZipCode = s.ZipCode,
City = s.City!
})
.ToListAsync(ct);
City = s.City!,
// 🔹 Liste des produits liés via Price
Products = s.Prices.Select(pr => new SupplierProductPriceDto
{
ProductId = pr.ProductId,
SellingPrice = pr.SellingPrice
}).ToList()
}).ToList();
await Send.OkAsync(responseDto, ct);
}

View File

@@ -1,4 +1,5 @@
using API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
@@ -9,7 +10,8 @@ public class GetSupplierRequest
public int Id { get; set; }
}
public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetSupplierRequest, GetSupplierDto>
public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
: Endpoint<GetSupplierRequest, GetSupplierDto>
{
public override void Configure()
{
@@ -19,9 +21,9 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
{
Models.Supplier? supplier = await pyrofetesdbcontext
.Suppliers
.SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct);
var supplier = await pyrofetesdbcontext.Suppliers
.Include(s => s.Prices)
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
if (supplier == null)
{
@@ -30,7 +32,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
return;
}
GetSupplierDto responseDto = new()
var responseDto = new GetSupplierDto
{
Id = supplier.Id,
Name = supplier.Name!,
@@ -38,7 +40,14 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
PhoneNumber = supplier.Phone!,
Adress = supplier.Address!,
ZipCode = supplier.ZipCode,
City = supplier.City!
City = supplier.City!,
// Produits liés
Products = supplier.Prices.Select(p => new SupplierProductPriceDto
{
ProductId = p.ProductId,
SellingPrice = p.SellingPrice
}).ToList()
};
await Send.OkAsync(responseDto, ct);

View File

@@ -1,7 +1,8 @@
using API.DTO.Supplier.Request;
using API.DTO.Supplier.Response;
using PyroFetes.DTO.Supplier.Request;
using PyroFetes.DTO.Supplier.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Supplier;
@@ -15,18 +16,16 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
{
Models.Supplier? supplierToEdit = await pyrofetesdbcontext
var supplierToEdit = await pyrofetesdbcontext
.Suppliers
.SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct);
.Include(s => s.Prices)
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
if (supplierToEdit == null)
if (supplierToEdit is null)
{
Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé.");
await Send.NotFoundAsync(ct);
return;
}
// Mise à jour des propriétés
supplierToEdit.Name = req.Name;
supplierToEdit.Email = req.Email;
supplierToEdit.Phone = req.PhoneNumber;
@@ -34,9 +33,28 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
supplierToEdit.ZipCode = req.ZipCode;
supplierToEdit.City = req.City;
if (req.Products is not null)
{
// Supprimer les anciennes liaisons
var existingPrices = pyrofetesdbcontext.Prices
.Where(p => p.SupplierId == supplierToEdit.Id);
pyrofetesdbcontext.Prices.RemoveRange(existingPrices);
// Ajouter les nouvelles liaisons
foreach (var p in req.Products)
{
pyrofetesdbcontext.Prices.Add(new Price
{
SupplierId = supplierToEdit.Id,
ProductId = p.ProductId,
SellingPrice = p.SellingPrice
});
}
}
await pyrofetesdbcontext.SaveChangesAsync(ct);
GetSupplierDto responseDto = new()
var response = new GetSupplierDto
{
Id = supplierToEdit.Id,
Name = supplierToEdit.Name,
@@ -47,6 +65,6 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
City = supplierToEdit.City
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,10 +1,12 @@
using API.DTO.Warehouse.Request;
using API.DTO.Warehouse.Response;
using FastEndpoints;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Warehouse;
public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateWarehouseDto, GetWarehouseDto>
public class CreateWarehouseEndpoint(PyroFetesDbContext db)
: Endpoint<CreateWarehouseDto, GetWarehouseDto>
{
public override void Configure()
{
@@ -14,7 +16,7 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct)
{
Models.Warehouse warehouse = new()
var warehouse = new Models.Warehouse
{
Name = req.Name,
MaxWeight = req.MaxWeight,
@@ -25,12 +27,26 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
City = req.City
};
pyrofetesdbcontext.Warehouses.Add(warehouse);
await pyrofetesdbcontext.SaveChangesAsync(ct);
db.Warehouses.Add(warehouse);
await db.SaveChangesAsync(ct);
Console.WriteLine("Entrepôt créé avec succès !");
// 🔹 Ajout des produits liés à cet entrepôt
if (req.Products is not null && req.Products.Any())
{
foreach (var p in req.Products)
{
var warehouseProduct = new WarehouseProduct
{
WarehouseId = warehouse.Id,
ProductId = p.ProductId,
Quantity = p.Quantity
};
db.WarehouseProducts.Add(warehouseProduct);
}
await db.SaveChangesAsync(ct);
}
GetWarehouseDto responseDto = new()
var response = new GetWarehouseDto
{
Id = warehouse.Id,
Name = warehouse.Name,
@@ -42,6 +58,6 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
City = warehouse.City
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,5 +1,6 @@
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Warehouse;
@@ -8,18 +9,20 @@ public class DeleteWarehouseRequest
public int Id { get; set; }
}
public class DeleteWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteWarehouseRequest>
public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint<DeleteWarehouseRequest>
{
public override void Configure()
{
// Lannotation correcte du paramètre est {id}, pas {@id}
Delete("/api/warehouse/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)
{
Models.Warehouse? warehouseToDelete = await pyrofetesdbcontext
.Warehouses
// On charge aussi les WarehouseProducts liés pour les supprimer proprement
var warehouseToDelete = await db.Warehouses
.Include(w => w.WarehouseProducts)
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
if (warehouseToDelete == null)
@@ -29,9 +32,21 @@ public class DeleteWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
return;
}
pyrofetesdbcontext.Warehouses.Remove(warehouseToDelete);
await pyrofetesdbcontext.SaveChangesAsync(ct);
// 🔹 Suppression des relations WarehouseProduct avant l'entrepôt
var relatedWarehouseProducts = await db.WarehouseProducts
.Where(wp => wp.WarehouseId == req.Id)
.ToListAsync(ct);
if (relatedWarehouseProducts.Any())
{
db.WarehouseProducts.RemoveRange(relatedWarehouseProducts);
}
// 🔹 Suppression de lentrepôt
db.Warehouses.Remove(warehouseToDelete);
await db.SaveChangesAsync(ct);
Console.WriteLine($"Entrepôt {warehouseToDelete.Name} (ID {req.Id}) supprimé avec succès.");
await Send.NoContentAsync(ct);
}
}

View File

@@ -1,10 +1,13 @@
using API.DTO.Warehouse.Response;
using API.DTO.Warehouse.Request;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Warehouse;
public class GetAllWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetWarehouseDto>>
public class GetAllWarehouseEndpoint(PyroFetesDbContext db)
: EndpointWithoutRequest<List<GetWarehouseDto>>
{
public override void Configure()
{
@@ -14,8 +17,13 @@ public class GetAllWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
public override async Task HandleAsync(CancellationToken ct)
{
List<GetWarehouseDto> responseDto = await pyrofetesdbcontext.Warehouses
.Select(w => new GetWarehouseDto
// 🔹 On inclut les relations avec WarehouseProducts et Product
var warehouses = await db.Warehouses
.Include(w => w.WarehouseProducts)
.ThenInclude(wp => wp.Product)
.ToListAsync(ct);
var response = warehouses.Select(w => new GetWarehouseDto
{
Id = w.Id,
Name = w.Name,
@@ -24,10 +32,15 @@ public class GetAllWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
MinWeight = w.MinWeight,
Adress = w.Address,
ZipCode = w.ZipCode,
City = w.City
})
.ToListAsync(ct);
City = w.City,
Products = w.WarehouseProducts.Select(wp => new WarehouseProductDto
{
ProductId = wp.ProductId,
ProductName = wp.Product?.Name,
Quantity = wp.Quantity
}).ToList()
}).ToList();
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -1,6 +1,7 @@
using API.DTO.Warehouse.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Warehouse;
@@ -9,18 +10,22 @@ public class GetWarehouseRequest
public int Id { get; set; }
}
public class GetWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetWarehouseRequest, GetWarehouseDto>
public class GetWarehouseEndpoint(PyroFetesDbContext db)
: Endpoint<GetWarehouseRequest, GetWarehouseDto>
{
public override void Configure()
{
// Pas de "@id" ici, juste {id}
Get("/api/warehouses/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(GetWarehouseRequest req, CancellationToken ct)
{
Models.Warehouse? warehouse = await pyrofetesdbcontext
.Warehouses
// 🔹 Inclut les produits associés à cet entrepôt
var warehouse = await db.Warehouses
.Include(w => w.WarehouseProducts)
.ThenInclude(wp => wp.Product)
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
if (warehouse == null)
@@ -30,7 +35,7 @@ public class GetWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
return;
}
GetWarehouseDto responseDto = new()
var response = new GetWarehouseDto
{
Id = warehouse.Id,
Name = warehouse.Name!,
@@ -39,9 +44,15 @@ public class GetWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
MinWeight = warehouse.MinWeight,
Adress = warehouse.Address!,
ZipCode = warehouse.ZipCode,
City = warehouse.City!
City = warehouse.City!,
Products = warehouse.WarehouseProducts.Select(wp => new WarehouseProductDto
{
ProductId = wp.ProductId,
ProductName = wp.Product?.Name,
Quantity = wp.Quantity
}).ToList()
};
await Send.OkAsync(responseDto, ct);
await Send.OkAsync(response, ct);
}
}

View File

@@ -2,21 +2,25 @@
using API.DTO.Warehouse.Response;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
namespace PyroFetes.Endpoints.Warehouse;
public class UpdateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateWarehouseDto, GetWarehouseDto>
public class UpdateWarehouseEndpoint(PyroFetesDbContext db)
: Endpoint<UpdateWarehouseDto, GetWarehouseDto>
{
public override void Configure()
{
// Utilise {id} plutôt que {@id}
Put("/api/warehouses/{@id}", x => new { x.Id });
AllowAnonymous();
}
public override async Task HandleAsync(UpdateWarehouseDto req, CancellationToken ct)
{
Models.Warehouse? warehouseToEdit = await pyrofetesdbcontext
.Warehouses
// 🔹 On inclut les produits existants pour pouvoir les modifier
var warehouseToEdit = await db.Warehouses
.Include(w => w.WarehouseProducts)
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
if (warehouseToEdit == null)
@@ -26,7 +30,7 @@ public class UpdateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
return;
}
// Mise à jour des champs
// 🔹 Mise à jour des champs de base
warehouseToEdit.Name = req.Name;
warehouseToEdit.MaxWeight = req.MaxWeight;
warehouseToEdit.Current = req.Current;
@@ -35,9 +39,30 @@ public class UpdateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
warehouseToEdit.ZipCode = req.ZipCode;
warehouseToEdit.City = req.City;
await pyrofetesdbcontext.SaveChangesAsync(ct);
// 🔹 Gestion des produits associés
if (req.Products is not null)
{
// On supprime les anciens liens pour recréer proprement
var existingLinks = warehouseToEdit.WarehouseProducts.ToList();
if (existingLinks.Any())
db.WarehouseProducts.RemoveRange(existingLinks);
GetWarehouseDto responseDto = new()
foreach (var p in req.Products)
{
var newLink = new WarehouseProduct
{
WarehouseId = warehouseToEdit.Id,
ProductId = p.ProductId,
Quantity = p.Quantity
};
db.WarehouseProducts.Add(newLink);
}
}
await db.SaveChangesAsync(ct);
// 🔹 On renvoie la version mise à jour
var response = new GetWarehouseDto
{
Id = warehouseToEdit.Id,
Name = warehouseToEdit.Name,
@@ -46,9 +71,16 @@ public class UpdateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
MinWeight = warehouseToEdit.MinWeight,
Adress = warehouseToEdit.Address,
ZipCode = warehouseToEdit.ZipCode,
City = warehouseToEdit.City
City = warehouseToEdit.City,
Products = warehouseToEdit.WarehouseProducts.Select(wp => new WarehouseProductDto
{
ProductId = wp.ProductId,
ProductName = wp.Product?.Name,
Quantity = wp.Quantity
}).ToList()
};
await Send.OkAsync(responseDto, ct);
Console.WriteLine($"Entrepôt {warehouseToEdit.Name} mis à jour avec succès.");
await Send.OkAsync(response, ct);
}
}

View File

@@ -4,13 +4,11 @@ namespace PyroFetes.Models;
public class Availability
{
//Champs
[Key] public int Id { get; set; }
[Required] public DateOnly AvailabilityDate { get; set; }
[Required] public DateOnly DeliveryDate { get; set; }
[Required] public DateOnly ExpirationDate { get; set; }
[Required] public DateOnly RenewallDate { get; set; }
//Relations
public List<StaffAvailability>? StaffAvailabilities { get; set; }
}

View File

@@ -4,11 +4,9 @@ namespace PyroFetes.Models;
public class Brand
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public int ProductId { get; set; }
//Relations
[Required] public int ProductId { get; set; }
[Required] public Product? Product { get; set; }
}

View File

@@ -4,11 +4,9 @@ namespace PyroFetes.Models;
public class City
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public int ZipCode { get; set; }
//Relations
public List<Show>? Shows { get; set; }
}

View File

@@ -4,10 +4,8 @@ namespace PyroFetes.Models;
public class Classification
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Label { get; set; }
//Relations
public List<Product>? Products { get; set; }
}

View File

@@ -4,10 +4,8 @@ namespace PyroFetes.Models;
public class Color
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Label { get; set; }
//Relations
public List<ProductColor>? ProductColors { get; set; }
}

View File

@@ -4,13 +4,11 @@ namespace PyroFetes.Models;
public class Communication
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Calling { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(300)] public string? Meeting { get; set; }
//Relations
[Required] public int ContactId { get; set; }
public Contact? Contact { get; set; }
}

View File

@@ -4,7 +4,6 @@ namespace PyroFetes.Models;
public class Contact
{
//Champs
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? LastName { get; set; }
[Required, MaxLength(100)] public string? FirstName { get; set; }
@@ -15,8 +14,6 @@ public class Contact
[Required, MaxLength(100)] public string? City { get; set; }
[Required, MaxLength(100)] public string? Role { get; set; }
//Relations
public Customer? Customer { get; set; }
[Required] public int CustomerId { get; set; }

View File

@@ -5,7 +5,7 @@ namespace PyroFetes.Models;
public class Material
{
[Key] public int Id {get; set;}
[Required, MaxLength(100)] public string? Label {get; set;}
[Required, MaxLength(100)] public string? Name {get; set;}
[Required] public int Quantity {get; set;}
[Required] public int WarehouseId {get; set;}

View File

@@ -9,7 +9,7 @@
<ItemGroup>
<PackageReference Include="FastEndpoints" Version="7.0.1" />
<PackageReference Include="FastEndpoints.Swagger" Version="7.0.1" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.20" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.19"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
<PrivateAssets>all</PrivateAssets>