From 1dcb3c35f261d29187543a4fe25661641c3413a5 Mon Sep 17 00:00:00 2001 From: colesm Date: Tue, 21 Apr 2026 10:27:00 +0200 Subject: [PATCH] MAJ update movement --- .../DTO/Movement/Request/CreateMovementDto.cs | 24 ++++++---- .../DTO/Product/Request/CreateProductDto.cs | 2 - .../Movement/CreateMovementEndpoint.cs | 5 +- .../Product/CreateProductEndpoint.cs | 1 - PyroFetes/Models/Movement.cs | 48 ++++++++++++++----- PyroFetes/Models/Product.cs | 9 ++-- PyroFetes/Program.cs | 2 + PyroFetes/PyroFetes.csproj | 9 ++-- PyroFetes/PyroFetesDbContext.cs | 4 +- 9 files changed, 66 insertions(+), 38 deletions(-) diff --git a/PyroFetes/DTO/Movement/Request/CreateMovementDto.cs b/PyroFetes/DTO/Movement/Request/CreateMovementDto.cs index 90afc746..e3691b1f 100644 --- a/PyroFetes/DTO/Movement/Request/CreateMovementDto.cs +++ b/PyroFetes/DTO/Movement/Request/CreateMovementDto.cs @@ -1,19 +1,23 @@ -// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux mouvements -namespace API.DTO.Movement.Request +using PyroFetes.Models; + +// Assure-toi d'importer tes enums + +namespace PyroFetes.DTO.Movement.Request { - // DTO utilisé pour créer un nouveau mouvement public class CreateMovementDto { - // Date à laquelle le mouvement est enregistré - public DateTime Date { get; set; } + public int ProductId { get; set; } - // Date et heure de début du mouvement + public MovementType Type { get; set; } + + public int Quantity { get; set; } + + public DateTime Date { get; set; } = DateTime.Now; public DateTime Start { get; set; } - - // Date et heure d'arrivée prévue du mouvement public DateTime Arrival { get; set; } - // Quantité de matériaux ou objets impliqués dans le mouvement - public int Quantity { get; set; } + public int? SourceWarehouseId { get; set; } + public int? DestinationWarehouseId { get; set; } + } } \ No newline at end of file diff --git a/PyroFetes/DTO/Product/Request/CreateProductDto.cs b/PyroFetes/DTO/Product/Request/CreateProductDto.cs index 6d67cecd..c85c545c 100644 --- a/PyroFetes/DTO/Product/Request/CreateProductDto.cs +++ b/PyroFetes/DTO/Product/Request/CreateProductDto.cs @@ -46,7 +46,5 @@ namespace PyroFetes.DTO.Product.Request // Liste des entrepôts liés au produit venant du DTO CreateProductWarehouseDto public List? Warehouses { get; set; } - - public int MovementId { get; set; } } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs index ee4cbb3a..0c24d700 100644 --- a/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs +++ b/PyroFetes/Endpoints/Movement/CreateMovementEndpoint.cs @@ -1,6 +1,7 @@ using API.DTO.Movement.Request; using API.DTO.Movement.Response; using FastEndpoints; +using PyroFetes.DTO.Movement.Request; namespace PyroFetes.Endpoints.Movement; @@ -17,9 +18,11 @@ public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End Models.Movement movement = new () { Date = req.Date, + ProductId = req.ProductId, Start = req.Start, Arrival = req.Arrival, - Quantity = req.Quantity + Quantity = req.Quantity, + Type = req.Type, }; pyrofetesdbcontext.Movements.Add(movement); diff --git a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs index de6ea723..82a83688 100644 --- a/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs +++ b/PyroFetes/Endpoints/Product/CreateProductEndpoint.cs @@ -29,7 +29,6 @@ public class CreateProductEndpoint(PyroFetesDbContext db) Link = req.Link!, ProductCategoryId = req.ProductCategoryId, ClassificationId = req.ClassificationId, - MovementId = req.MovementId }; db.Products.Add(product); diff --git a/PyroFetes/Models/Movement.cs b/PyroFetes/Models/Movement.cs index fe26f187..8fe98852 100644 --- a/PyroFetes/Models/Movement.cs +++ b/PyroFetes/Models/Movement.cs @@ -2,18 +2,42 @@ namespace PyroFetes.Models; +// 1. Définition des types possibles pour la logique métier +public enum MovementType +{ + Entry, // Entrée (ex: Achat fournisseur) + Exit, // Sortie (ex: Vente, Casse) + Transfer, // Transfert entre deux entrepôts + Inventory // Ajustement manuel +} + public class Movement { - [Key] public int Id { get; set; } - [Required] public DateTime Date { get; set; } - [Required] public DateTime Start {get; set;} - [Required] public DateTime Arrival {get; set;} - [Required] public int Quantity {get; set;} - - public List? Products { get; set; } - - public int? SourceWarehouseId {get; set;} - public Warehouse? SourceWarehouse {get; set;} - public int? DestinationWarehouseId {get; set;} - public Warehouse? DestinationWarehouse {get; set;} + [Key] + public int Id { get; set; } + + [Required] + public DateTime Date { get; set; } = DateTime.Now; + + public DateTime Start { get; set; } + public DateTime Arrival { get; set; } + + [Required] + public int Quantity { get; set; } + + [Required] + public MovementType Type { get; set; } + + [Required] + public int ProductId { get; set; } + public Product? Product { get; set; } + + public int? SourceWarehouseId { get; set; } + public Warehouse? SourceWarehouse { get; set; } + + public int? DestinationWarehouseId { get; set; } + public Warehouse? DestinationWarehouse { get; set; } + + [MaxLength(500)] + public string? Comment { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Models/Product.cs b/PyroFetes/Models/Product.cs index ec603601..3d37e98b 100644 --- a/PyroFetes/Models/Product.cs +++ b/PyroFetes/Models/Product.cs @@ -12,9 +12,9 @@ namespace PyroFetes.Models [Required, MaxLength(100)] public string? ApprovalNumber { get; set; } [Required] public decimal Weight { get; set; } [Required] public decimal Nec { get; set; } - [Required] public string? Image { get; set; } - [Required, MaxLength(200)] public string? Link { get; set; } - [Required] public int MinimalQuantity { get; set; } + public string? Image { get; set; } + [MaxLength(200)] public string? Link { get; set; } + public int MinimalQuantity { get; set; } // Relations [Required] public int ClassificationId { get; set; } @@ -23,8 +23,7 @@ namespace PyroFetes.Models [Required] public int ProductCategoryId { get; set; } public ProductCategory? ProductCategory { get; set; } - [Required] public int MovementId {get; set;} - public Movement? Movement {get; set;} + public List? Movements { get; set; } public List? ProductDeliveries { get; set; } public List? Brands { get; set; } diff --git a/PyroFetes/Program.cs b/PyroFetes/Program.cs index 85e834ab..ba56fccc 100644 --- a/PyroFetes/Program.cs +++ b/PyroFetes/Program.cs @@ -4,6 +4,8 @@ using FastEndpoints.Swagger; using Microsoft.EntityFrameworkCore; using PyroFetes; + + WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.Services diff --git a/PyroFetes/PyroFetes.csproj b/PyroFetes/PyroFetes.csproj index a74e16bc..01d91379 100644 --- a/PyroFetes/PyroFetes.csproj +++ b/PyroFetes/PyroFetes.csproj @@ -2,6 +2,7 @@ net8.0 + Major enable enable @@ -14,16 +15,12 @@ - all - runtime; build; native; contentfiles; analyzers; buildtransitive + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - diff --git a/PyroFetes/PyroFetesDbContext.cs b/PyroFetes/PyroFetesDbContext.cs index 35f25bb0..38d0e15d 100644 --- a/PyroFetes/PyroFetesDbContext.cs +++ b/PyroFetes/PyroFetesDbContext.cs @@ -6,6 +6,8 @@ namespace PyroFetes; public class PyroFetesDbContext : DbContext { + + // Entities public DbSet Availabilities { get; set; } public DbSet Brands { get; set; } @@ -55,7 +57,7 @@ public class PyroFetesDbContext : DbContext { string connectionString = "Server=romaric-thibault.fr;" + - "Database=Pyromana;" + + "Database=PyroMana;" + "User Id=matheo;" + "Password=Onto9-Cage-Afflicted;" + "TrustServerCertificate=true;";