forked from sanchezvem/PyroFetes
Compare commits
33 Commits
f155d03559
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 94df917149 | |||
| 0a8258017a | |||
| 78e5a4e960 | |||
| f60d3443ca | |||
| cd7bfe618a | |||
| 038b0aa26d | |||
| 157719eae2 | |||
| a8d0b99571 | |||
| cb55f55c73 | |||
| 8699ac7437 | |||
| 4c0e7df9de | |||
| 5506eab8ff | |||
| 15545980af | |||
| dda2240e86 | |||
| a014c6c9f7 | |||
| 2112605cf3 | |||
| 90d685d42c | |||
| 2bcca6f856 | |||
| 6d564c89ff | |||
| bad259e9f5 | |||
| 32dee6eb18 | |||
| b3347fe163 | |||
| 0e74cb40f5 | |||
| 91b4aca2fa | |||
| 1734ec0219 | |||
| 7a8daa6ab8 | |||
| 8f4171a045 | |||
| 8a8a47c99c | |||
| bb5dd63da2 | |||
| c5805d979b | |||
| 44da6ed371 | |||
| 08bf910437 | |||
| d1fa3aca68 |
@@ -1,7 +1,9 @@
|
|||||||
namespace API.DTO.Brand.Request;
|
namespace PyroFetes.DTO.Brand.Request
|
||||||
|
|
||||||
public class CreateBrandDto
|
|
||||||
{
|
{
|
||||||
public string? Name { get; set; }
|
// DTO pour créer une nouvelle marque
|
||||||
|
public class CreateBrandDto
|
||||||
|
{
|
||||||
|
// Nom de la marque
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
namespace API.DTO.Brand.Request;
|
namespace PyroFetes.DTO.Brand.Request
|
||||||
|
|
||||||
public class UpdateBrandDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour mettre à jour une marque existante
|
||||||
public string? Name { get; set; }
|
public class UpdateBrandDto
|
||||||
|
{
|
||||||
|
// Identifiant de la marque à mettre à jour
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nouveau nom de la marque
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
namespace API.DTO.Brand.Response;
|
namespace API.DTO.Brand.Response
|
||||||
|
|
||||||
public class GetBrandDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour récupérer les informations d'une marque
|
||||||
public string? Name { get; set; }
|
public class GetBrandDto
|
||||||
|
{
|
||||||
|
// Identifiant de la marque
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom de la marque
|
||||||
|
public string? Name { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
namespace API.DTO.Classification.Request;
|
// Définition de l'espace de noms pour les DTO liés à la création de classifications
|
||||||
|
namespace API.DTO.Classification.Request
|
||||||
public class CreateClassificationDto
|
|
||||||
{
|
{
|
||||||
public string? Label { get; set; }
|
// DTO (Data Transfer Object) utilisé pour créer une nouvelle classification
|
||||||
|
public class CreateClassificationDto
|
||||||
|
{
|
||||||
|
// Propriété représentant le nom ou le label de la classification
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
namespace API.DTO.Classification.Request;
|
// Définition de l'espace de noms pour les DTO liés à la mise à jour de classifications
|
||||||
|
namespace API.DTO.Classification.Request
|
||||||
public class UpdateClassificationDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO (Data Transfer Object) utilisé pour mettre à jour une classification existante
|
||||||
public string? Label { get; set; }
|
public class UpdateClassificationDto
|
||||||
|
{
|
||||||
|
// Propriété représentant l'ID unique de la classification à mettre à jour
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Propriété représentant le nouveau nom ou label de la classification
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null
|
||||||
|
// Si null, le label ne sera pas modifié
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,14 @@
|
|||||||
namespace API.DTO.Classification.Response;
|
// Définition de l'espace de noms pour les DTO utilisés dans les réponses liées aux classifications
|
||||||
|
namespace API.DTO.Classification.Response
|
||||||
public class GetClassificationDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO (Data Transfer Object) utilisé pour renvoyer les informations d'une classification
|
||||||
public string? Label { get; set; }
|
public class GetClassificationDto
|
||||||
|
{
|
||||||
|
// Propriété représentant l'ID unique de la classification
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Propriété représentant le nom ou label de la classification
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si la classification n'a pas de label
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
namespace API.DTO.Color.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux couleurs
|
||||||
|
namespace API.DTO.Color.Request
|
||||||
public class CreateColorDto
|
|
||||||
{
|
{
|
||||||
public string? Label { get; set; }
|
// DTO utilisé pour créer une nouvelle couleur
|
||||||
|
public class CreateColorDto
|
||||||
|
{
|
||||||
|
// Propriété représentant le nom ou label de la couleur à créer
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si le label n'est pas fourni
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
namespace API.DTO.Color.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux couleurs
|
||||||
|
namespace API.DTO.Color.Request
|
||||||
public class UpdateColorDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour mettre à jour une couleur existante
|
||||||
public string? Label { get; set; }
|
public class UpdateColorDto
|
||||||
|
{
|
||||||
|
// Identifiant unique de la couleur à mettre à jour
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nouveau nom ou label de la couleur
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucun changement n'est fourni
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
namespace API.DTO.Color.Response;
|
// Définition de l'espace de noms pour les DTO utilisés dans les réponses liées aux couleurs
|
||||||
|
namespace API.DTO.Color.Response
|
||||||
public class GetColorDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour renvoyer les informations d'une couleur
|
||||||
public string? Label { get; set; }
|
public class GetColorDto
|
||||||
|
{
|
||||||
|
// Identifiant unique de la couleur
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom ou label de la couleur
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si le label n'est pas défini
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
namespace API.DTO.Effect.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux effets
|
||||||
|
namespace API.DTO.Effect.Request
|
||||||
public class CreateEffectDto
|
|
||||||
{
|
{
|
||||||
public string? Label { get; set; }
|
// DTO utilisé pour créer un nouvel effet
|
||||||
|
public class CreateEffectDto
|
||||||
|
{
|
||||||
|
// Nom ou label de l'effet
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucun label n'est fourni
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
namespace API.DTO.Effect.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux effets
|
||||||
|
namespace API.DTO.Effect.Request
|
||||||
public class UpdateEffectDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour mettre à jour un effet existant
|
||||||
public string? Label { get; set; }
|
public class UpdateEffectDto
|
||||||
|
{
|
||||||
|
// Identifiant unique de l'effet à mettre à jour
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nouveau nom ou label de l'effet
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucun label n'est fourni
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,14 @@
|
|||||||
namespace API.DTO.Effect.Response;
|
// Définition de l'espace de noms pour les DTO utilisés dans les réponses liées aux effets
|
||||||
|
namespace API.DTO.Effect.Response
|
||||||
public class GetEffectDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour renvoyer les informations d'un effet
|
||||||
public string? Label { get; set; }
|
public class GetEffectDto
|
||||||
|
{
|
||||||
|
// Identifiant unique de l'effet
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom ou label de l'effet
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucune valeur n'est disponible
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
7
PyroFetes/DTO/Login/Request/ConnectLoginDto.cs
Normal file
7
PyroFetes/DTO/Login/Request/ConnectLoginDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.Login.Request;
|
||||||
|
|
||||||
|
public class ConnectLoginDto
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
24
PyroFetes/DTO/Login/Request/CreateLoginDto.cs
Normal file
24
PyroFetes/DTO/Login/Request/CreateLoginDto.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
// Nécessaire pour les validations
|
||||||
|
|
||||||
|
namespace PyroFetes.DTO.Login.Request;
|
||||||
|
|
||||||
|
public class CreateLoginDto
|
||||||
|
{
|
||||||
|
[Required(ErrorMessage = "Le nom est requis.")]
|
||||||
|
[StringLength(50, MinimumLength = 3, ErrorMessage = "L'identifiant doit faire entre 3 et 50 caractères.")]
|
||||||
|
public string Name { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "L'emil est requis.")]
|
||||||
|
[StringLength(50, MinimumLength = 3)]
|
||||||
|
public string Email { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[Required(ErrorMessage = "Le mot de passe est requis.")]
|
||||||
|
[MinLength(6, ErrorMessage = "Le mot de passe doit contenir au moins 6 caractères.")]
|
||||||
|
public string Password { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
// Ajout du champ Rôle (Optionnel, par défaut "User")
|
||||||
|
// Cela te permet d'envoyer "Admin" via Swagger
|
||||||
|
public string Fonction { get; set; } = "User";
|
||||||
|
}
|
||||||
8
PyroFetes/DTO/Login/Request/UpdateLoginDto.cs
Normal file
8
PyroFetes/DTO/Login/Request/UpdateLoginDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PyroFetes.DTO.Login.Request;
|
||||||
|
|
||||||
|
public class UpdateLoginDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs
Normal file
6
PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
public class GetLoginConnectDto
|
||||||
|
{
|
||||||
|
public string? Token { get; set; }
|
||||||
|
}
|
||||||
10
PyroFetes/DTO/Login/Response/GetLoginDto.cs
Normal file
10
PyroFetes/DTO/Login/Response/GetLoginDto.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
public class GetLoginDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string? Name { get; set; } = string.Empty;
|
||||||
|
public string? Email { get; set; } = string.Empty;
|
||||||
|
public string? Password { get; set; } = string.Empty;
|
||||||
|
public string? Fonction { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
namespace API.DTO.Material.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux matériaux
|
||||||
|
namespace API.DTO.Material.Request
|
||||||
public class CreateMaterialDto
|
|
||||||
{
|
{
|
||||||
public string? Label { get; set; }
|
// DTO utilisé pour créer un nouveau matériau
|
||||||
public int Quantity { get; set; }
|
public class CreateMaterialDto
|
||||||
public int WarehouseId {get; set;}
|
{
|
||||||
|
// Nom ou label du matériau
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucune valeur n'est fournie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
|
||||||
|
// Quantité du matériau à créer
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de l'entrepôt dans lequel le matériau sera stocké
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
namespace API.DTO.Material.Request;
|
// Définition de l'espace de noms pour les DTO utilisés dans les requêtes liées aux matériaux
|
||||||
|
namespace API.DTO.Material.Request
|
||||||
public class UpdateMaterialDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour mettre à jour un matériau existant
|
||||||
public string? Label { get; set; }
|
public class UpdateMaterialDto
|
||||||
public int Quantity { get; set; }
|
{
|
||||||
public int WarehouseId {get; set;}
|
// Identifiant unique du matériau à mettre à jour
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom ou label du matériau
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucune valeur n'est fournie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
|
||||||
|
// Quantité mise à jour du matériau
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de l'entrepôt associé au matériau
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
namespace API.DTO.Material.Response;
|
// Définition de l'espace de noms pour les DTO utilisés dans les réponses liées aux matériaux
|
||||||
|
namespace API.DTO.Material.Response
|
||||||
public class GetMaterialDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour renvoyer les informations d'un matériau
|
||||||
public string? Label { get; set; }
|
public class GetMaterialDto
|
||||||
public int Quantity { get; set; }
|
{
|
||||||
public int WarehouseId {get; set;}
|
// Identifiant unique du matériau
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom ou label du matériau
|
||||||
|
// Le type "string?" signifie que cette valeur peut être null si aucune valeur n'est définie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
|
||||||
|
// Quantité disponible du matériau
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de l'entrepôt auquel le matériau est associé
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,19 @@
|
|||||||
namespace API.DTO.Movement.Request;
|
// 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
|
||||||
public class CreateMovementDto
|
|
||||||
{
|
{
|
||||||
public DateTime Date { get; set; }
|
// DTO utilisé pour créer un nouveau mouvement
|
||||||
public DateTime Start {get; set;}
|
public class CreateMovementDto
|
||||||
public DateTime Arrival {get; set;}
|
{
|
||||||
public int Quantity {get; set;}
|
// Date à laquelle le mouvement est enregistré
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
// Date et heure de début du mouvement
|
||||||
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
namespace API.DTO.Movement.Request;
|
// 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
|
||||||
public class UpdateMovementDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour mettre à jour un mouvement existant
|
||||||
public DateTime Date { get; set; }
|
public class UpdateMovementDto
|
||||||
public DateTime Start {get; set;}
|
{
|
||||||
public DateTime Arrival {get; set;}
|
// ID unique du mouvement à mettre à jour
|
||||||
public int Quantity {get; set;}
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Date à laquelle le mouvement est enregistré
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
// Date et heure de début du mouvement
|
||||||
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,22 @@
|
|||||||
namespace API.DTO.Movement.Response;
|
// Définition de l'espace de noms pour les DTO utilisés dans les réponses liées aux mouvements
|
||||||
|
namespace API.DTO.Movement.Response
|
||||||
public class GetMovementDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour renvoyer les informations d'un mouvement
|
||||||
public DateTime Date { get; set; }
|
public class GetMovementDto
|
||||||
public DateTime Start {get; set;}
|
{
|
||||||
public DateTime Arrival {get; set;}
|
// ID unique du mouvement
|
||||||
public int Quantity {get; set;}
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Date à laquelle le mouvement est enregistré
|
||||||
|
public DateTime Date { get; set; }
|
||||||
|
|
||||||
|
// Date et heure de début du mouvement
|
||||||
|
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; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,50 @@
|
|||||||
using PyroFetes.Models;
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Request;
|
namespace PyroFetes.DTO.Product.Request
|
||||||
|
|
||||||
public class CreateProductDto
|
|
||||||
{
|
{
|
||||||
public int References { get; set; }
|
// DTO utilisé lors de la création d’un produit
|
||||||
public string? Name { get; set; }
|
public class CreateProductDto
|
||||||
public decimal Duration { get; set; }
|
{
|
||||||
public decimal Caliber { get; set; }
|
// Référence interne du produit
|
||||||
public int ApprovalNumber { get; set; }
|
public string? Reference { get; set; }
|
||||||
public decimal Weight { get; set; }
|
|
||||||
public decimal Nec { get; set; }
|
// Nom du produit
|
||||||
public decimal SellingPrice {get; set;}
|
public string? Name { get; set; }
|
||||||
public string? Image { get; set; }
|
|
||||||
public string? Link { get; set; }
|
// Durée de l’effet du produit
|
||||||
|
public decimal Duration { get; set; }
|
||||||
public int ClassificationId { get; set;}
|
|
||||||
public int ProductCategoryId { get; set; }
|
// Calibre du produit
|
||||||
|
public int Caliber { get; set; }
|
||||||
|
|
||||||
|
// Numéro d’homologation
|
||||||
|
public string? ApprovalNumber { get; set; }
|
||||||
|
|
||||||
|
// Poids du produit
|
||||||
|
public decimal Weight { get; set; }
|
||||||
|
|
||||||
|
// Matière active (NEC)
|
||||||
|
public decimal Nec { get; set; }
|
||||||
|
|
||||||
|
// Prix de vente du produit
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
|
||||||
|
// Image associée au produit (URL ou chemin)
|
||||||
|
public string? Image { get; set; }
|
||||||
|
|
||||||
|
// Lien vers une ressource externe (vidéo, fiche, etc.)
|
||||||
|
public string? Link { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la classification du produit
|
||||||
|
public int ClassificationId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la catégorie du produit
|
||||||
|
public int ProductCategoryId { get; set; }
|
||||||
|
|
||||||
|
// Liste des fournisseurs liés au produit venant du DTO ProductSupplierPriceDto
|
||||||
|
public List<ProductSupplierPriceDto>? Suppliers { get; set; }
|
||||||
|
|
||||||
|
// Liste des entrepôts liés au produit venant du DTO CreateProductWarehouseDto
|
||||||
|
public List<CreateProductWarehouseDto>? Warehouses { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,53 @@
|
|||||||
using PyroFetes.Models;
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Request;
|
namespace PyroFetes.DTO.Product.Request
|
||||||
|
|
||||||
public class UpdateProductDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour la mise à jour d’un produit existant
|
||||||
public int Reference { get; set; }
|
public class UpdateProductDto
|
||||||
public string? Name { get; set; }
|
{
|
||||||
public decimal Duration { get; set; }
|
// Identifiant unique du produit à modifier
|
||||||
public decimal Caliber { get; set; }
|
public int Id { get; set; }
|
||||||
public int ApprovalNumber { get; set; }
|
|
||||||
public decimal Weight { get; set; }
|
// Référence interne du produit
|
||||||
public decimal Nec { get; set; }
|
public string? Reference { get; set; }
|
||||||
public decimal SellingPrice {get; set;}
|
|
||||||
public string? Image { get; set; }
|
// Nom du produit
|
||||||
public string? Link { get; set; }
|
public string? Name { get; set; }
|
||||||
public int ClassificationId { get; set;}
|
|
||||||
public int ProductCategoryId { get; set; }
|
// Durée de l’effet du produit
|
||||||
|
public decimal Duration { get; set; }
|
||||||
|
|
||||||
|
// Calibre du produit
|
||||||
|
public int Caliber { get; set; }
|
||||||
|
|
||||||
|
// Numéro d’homologation
|
||||||
|
public string? ApprovalNumber { get; set; }
|
||||||
|
|
||||||
|
// Poids du produit
|
||||||
|
public decimal Weight { get; set; }
|
||||||
|
|
||||||
|
// Matière active (NEC)
|
||||||
|
public decimal Nec { get; set; }
|
||||||
|
|
||||||
|
// Prix de vente du produit
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
|
||||||
|
// Image associée au produit (URL ou chemin)
|
||||||
|
public string? Image { get; set; }
|
||||||
|
|
||||||
|
// Lien vers une ressource externe (fiche, vidéo, etc.)
|
||||||
|
public string? Link { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la classification du produit
|
||||||
|
public int ClassificationId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la catégorie du produit
|
||||||
|
public int ProductCategoryId { get; set; }
|
||||||
|
|
||||||
|
// Liste des fournisseurs associés venant du DTO ProductSupplierPriceDto
|
||||||
|
public List<ProductSupplierPriceDto> Suppliers { get; set; } = new();
|
||||||
|
|
||||||
|
// Liste des entrepôts associés venant du DTO UpdateProductWarehouseDto
|
||||||
|
public List<UpdateProductWarehouseDto> Warehouses { get; set; } = new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,54 @@
|
|||||||
using PyroFetes.Models;
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Response;
|
namespace PyroFetes.DTO.Product.Response
|
||||||
|
|
||||||
public class GetProductDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO utilisé pour renvoyer les informations complètes d’un produit
|
||||||
public int Reference { get; set; }
|
public class GetProductDto
|
||||||
public string? Name { get; set; }
|
{
|
||||||
public decimal Duration { get; set; }
|
// Identifiant unique du produit
|
||||||
public decimal Caliber { get; set; }
|
public int Id { get; set; }
|
||||||
public int ApprovalNumber { get; set; }
|
|
||||||
public decimal Weight { get; set; }
|
// Référence interne du produit
|
||||||
public decimal Nec { get; set; }
|
public string? Reference { get; set; }
|
||||||
public decimal SellingPrice {get; set;}
|
|
||||||
public string? Image { get; set; }
|
// Nom du produit
|
||||||
public string? Link { get; set; }
|
public string? Name { get; set; }
|
||||||
public int ClassificationId { get; set;}
|
|
||||||
public string? ClassificationLabel { get; set; }
|
// Durée de l’effet du produit
|
||||||
public int ProductCategoryId { get; set; }
|
public decimal Duration { get; set; }
|
||||||
public string? ProductCategoryLabel { get; set; }
|
|
||||||
|
// Calibre du produit
|
||||||
|
public int Caliber { get; set; }
|
||||||
|
|
||||||
|
// Numéro d’homologation
|
||||||
|
public string? ApprovalNumber { get; set; }
|
||||||
|
|
||||||
|
// Poids du produit
|
||||||
|
public decimal Weight { get; set; }
|
||||||
|
|
||||||
|
// Matière active (NEC)
|
||||||
|
public decimal Nec { get; set; }
|
||||||
|
|
||||||
|
// Prix de vente du produit
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
|
||||||
|
// Image du produit (URL ou chemin)
|
||||||
|
public string? Image { get; set; }
|
||||||
|
|
||||||
|
// Lien externe vers plus d’informations (fiche, vidéo, etc.)
|
||||||
|
public string? Link { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la classification du produit
|
||||||
|
public int ClassificationId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la catégorie du produit
|
||||||
|
public int ProductCategoryId { get; set; }
|
||||||
|
|
||||||
|
// Fournisseurs liés venant du DTO ProductSupplierPriceDto
|
||||||
|
public List<ProductSupplierPriceDto> Suppliers { get; set; } = new();
|
||||||
|
|
||||||
|
// Entrepôts liés venant du DTO ProductWarehouseDto
|
||||||
|
public List<GetProductWarehouseDto> Warehouses { get; set; } = new();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
namespace API.DTO.ProductCategory.Request;
|
namespace API.DTO.ProductCategory.Request
|
||||||
|
|
||||||
public class CreateProductCategoryDto
|
|
||||||
{
|
{
|
||||||
public string? Label { get; set; }
|
// DTO pour créer une catégorie de produit
|
||||||
|
public class CreateProductCategoryDto
|
||||||
|
{
|
||||||
|
// Nom de la catégorie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
namespace API.DTO.ProductCategory.Request;
|
namespace API.DTO.ProductCategory.Request
|
||||||
|
|
||||||
public class UpdateProductCategoryDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour mettre à jour une catégorie de produit
|
||||||
public string? Label { get; set; }
|
public class UpdateProductCategoryDto
|
||||||
|
{
|
||||||
|
// Identifiant de la catégorie
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom de la catégorie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
namespace API.DTO.ProductCategory.Response;
|
namespace API.DTO.ProductCategory.Response
|
||||||
|
|
||||||
public class GetProductCategoryDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour récupérer une catégorie de produit
|
||||||
public string? Label { get; set; }
|
public class GetProductCategoryDto
|
||||||
|
{
|
||||||
|
// Identifiant de la catégorie
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
// Nom de la catégorie
|
||||||
|
public string? Label { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
7
PyroFetes/DTO/ProductColor/Request/ProductColorDto.cs
Normal file
7
PyroFetes/DTO/ProductColor/Request/ProductColorDto.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace PyroFetes.DTO.ProductColor.Request;
|
||||||
|
// DTO utilisé pour créer ou mettre à jour la relation Product <-> Color
|
||||||
|
public class ProductColorDto
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; } // Id du produit (pour update)
|
||||||
|
public int ColorId { get; set; } // Id de la couleur
|
||||||
|
}
|
||||||
11
PyroFetes/DTO/ProductColor/Response/GetProductColorDto.cs
Normal file
11
PyroFetes/DTO/ProductColor/Response/GetProductColorDto.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
namespace PyroFetes.DTO.ProductColor.Response;
|
||||||
|
// DTO utilisé pour renvoyer les informations d’un produit lié à une couleur
|
||||||
|
|
||||||
|
public class GetProductColorDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit concerné
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de la couleur
|
||||||
|
public int ColorId { get; set; }
|
||||||
|
}
|
||||||
8
PyroFetes/DTO/ProductEffect/Request/ProductEffectDto.cs
Normal file
8
PyroFetes/DTO/ProductEffect/Request/ProductEffectDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace PyroFetes.DTO.ProductEffect.Request;
|
||||||
|
|
||||||
|
// DTO utilisé pour créer ou mettre à jour la relation Product <-> Effect
|
||||||
|
public class ProductEffectDto
|
||||||
|
{
|
||||||
|
public int ProductId { get; set; } // Id du produit (pour update)
|
||||||
|
public int EffectId { get; set; } // Id de l'effet
|
||||||
|
}
|
||||||
12
PyroFetes/DTO/ProductEffect/Response/GetProductEffectDto.cs
Normal file
12
PyroFetes/DTO/ProductEffect/Response/GetProductEffectDto.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
namespace PyroFetes.DTO.ProductEffect.Response;
|
||||||
|
|
||||||
|
// DTO utilisé pour renvoyer les informations d’un produit lié à un effet
|
||||||
|
|
||||||
|
public class GetProductEffectDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit concerné
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant de l'effet
|
||||||
|
public int EffectId { get; set; }
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace PyroFetes.DTO.Product.Response
|
||||||
|
{
|
||||||
|
// DTO utilisé pour renvoyer les informations d’un fournisseur lié à un produit
|
||||||
|
public class GetProductSupplierDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit concerné
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant du fournisseur
|
||||||
|
public int SupplierId { get; set; }
|
||||||
|
|
||||||
|
// Nom du fournisseur
|
||||||
|
public string SupplierName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
// Prix de vente du produit fourni par ce fournisseur
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
namespace PyroFetes.DTO.Product.Request
|
||||||
|
{
|
||||||
|
// DTO utilisé lors de la création d’une relation entre un produit et un entrepôt
|
||||||
|
public class CreateProductWarehouseDto
|
||||||
|
{
|
||||||
|
// Identifiant de l'entrepôt concerné
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant du produit associé à cet entrepôt
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Quantité du produit disponible dans cet entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO utilisé lors de la mise à jour d’une relation entre un produit et un entrepôt
|
||||||
|
public class UpdateProductWarehouseDto
|
||||||
|
{
|
||||||
|
// Identifiant de l'entrepôt concerné
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant du produit associé à cet entrepôt
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Nouvelle quantité du produit dans cet entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace PyroFetes.DTO.Product.Response
|
||||||
|
{
|
||||||
|
// DTO utilisé pour renvoyer les informations d’un entrepôt lié à un produit
|
||||||
|
public class GetProductWarehouseDto
|
||||||
|
{
|
||||||
|
// Identifiant de l'entrepôt
|
||||||
|
public int WarehouseId { get; set; }
|
||||||
|
|
||||||
|
// Identifiant du produit associé à cet entrepôt
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Nom de l'entrepôt (utile pour l’affichage)
|
||||||
|
public string WarehouseName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
// Quantité du produit stockée dans cet entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Refrresh/Request/RefreshTokenDto.cs
Normal file
6
PyroFetes/DTO/Refrresh/Request/RefreshTokenDto.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Refrresh.Request;
|
||||||
|
|
||||||
|
public class RefreshTokenDto
|
||||||
|
{
|
||||||
|
public string? Token { get; set; }
|
||||||
|
}
|
||||||
6
PyroFetes/DTO/Refrresh/Response/GetRefreshDto.cs
Normal file
6
PyroFetes/DTO/Refrresh/Response/GetRefreshDto.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PyroFetes.DTO.Refrresh.Response;
|
||||||
|
|
||||||
|
public class GetRefreshDto
|
||||||
|
{
|
||||||
|
public string? Token { get; set; }
|
||||||
|
}
|
||||||
@@ -1,11 +1,37 @@
|
|||||||
namespace API.DTO.Supplier.Request;
|
namespace PyroFetes.DTO.Supplier.Request
|
||||||
|
|
||||||
public class CreateSupplierDto
|
|
||||||
{
|
{
|
||||||
public string Name { get; set; }
|
// DTO pour créer un nouveau fournisseur
|
||||||
public string Email { get; set; }
|
public class CreateSupplierDto
|
||||||
public string PhoneNumber { get; set; }
|
{
|
||||||
public string Adress { get; set; }
|
// Nom du fournisseur
|
||||||
public int ZipCode { get; set; }
|
public string? Name { get; set; }
|
||||||
public string City { get; set; }
|
|
||||||
|
// Email du fournisseur
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
// Numéro de téléphone du fournisseur
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
// Adresse du fournisseur
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal de l'adresse
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville de l'adresse
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits fournis par ce fournisseur dans la classe SupplierProductPriceDto
|
||||||
|
public List<SupplierProductPriceDto>? Products { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO pour relier un produit et son prix à un fournisseur
|
||||||
|
public class SupplierProductPriceDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit fourni
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Prix de vente du produit par ce fournisseur
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,30 @@
|
|||||||
namespace API.DTO.Supplier.Request;
|
namespace PyroFetes.DTO.Supplier.Request
|
||||||
|
|
||||||
public class UpdateSupplierDto
|
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour mettre à jour un fournisseur existant
|
||||||
public string Name { get; set; }
|
public class UpdateSupplierDto
|
||||||
public string Email { get; set; }
|
{
|
||||||
public string PhoneNumber { get; set; }
|
// Identifiant du fournisseur à mettre à jour
|
||||||
public string Adress { get; set; }
|
public int Id { get; set; }
|
||||||
public int ZipCode { get; set; }
|
|
||||||
public string City { get; set; }
|
// Nom du fournisseur
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
// Email du fournisseur
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
// Numéro de téléphone du fournisseur
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
// Adresse du fournisseur
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal de l'adresse
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville de l'adresse
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits fournis par ce fournisseur relié à la classe SupplierProductPriceDto
|
||||||
|
public List<SupplierProductPriceDto>? Products { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,45 @@
|
|||||||
namespace API.DTO.Supplier.Response;
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
|
||||||
public class GetSupplierDto
|
namespace PyroFetes.DTO.Supplier.Response
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
// DTO pour récupérer les informations d'un fournisseur
|
||||||
public string Name { get; set; }
|
public class GetSupplierDto
|
||||||
public string Email { get; set; }
|
{
|
||||||
public string PhoneNumber { get; set; }
|
// Identifiant du fournisseur
|
||||||
public string Adress { get; set; }
|
public int Id { get; set; }
|
||||||
public int ZipCode { get; set; }
|
|
||||||
public string City { get; set; }
|
// Nom du fournisseur
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
// Email du fournisseur
|
||||||
|
public string? Email { get; set; }
|
||||||
|
|
||||||
|
// Numéro de téléphone
|
||||||
|
public string? PhoneNumber { get; set; }
|
||||||
|
|
||||||
|
// Adresse du fournisseur
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits fournis par la classe SupplierProductPriceDto
|
||||||
|
public List<SupplierProductPriceDto> Products { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO pour les détails d'un produit lié à un fournisseur
|
||||||
|
public class GetSupplierProductDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Nom du produit
|
||||||
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
// Prix de vente fourni par le fournisseur
|
||||||
|
public decimal SellingPrice { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,40 @@
|
|||||||
namespace API.DTO.Warehouse.Request;
|
namespace API.DTO.Warehouse.Request
|
||||||
|
|
||||||
public class CreateWarehouseDto
|
|
||||||
{
|
{
|
||||||
public string Name {get; set;}
|
// DTO pour créer un entrepôt
|
||||||
public int MaxWeight {get; set;}
|
public class CreateWarehouseDto
|
||||||
public int Current {get; set;}
|
{
|
||||||
public int MinWeight {get; set;}
|
// Nom de l'entrepôt
|
||||||
public string Adress { get; set; }
|
public string? Name { get; set; }
|
||||||
public int ZipCode { get; set; }
|
|
||||||
public string City { get; set; }
|
// Poids maximal que l'entrepôt peut contenir
|
||||||
}
|
public int MaxWeight { get; set; }
|
||||||
|
|
||||||
|
// Poids actuel stocké
|
||||||
|
public int Current { get; set; }
|
||||||
|
|
||||||
|
// Poids minimal souhaité
|
||||||
|
public int MinWeight { get; set; }
|
||||||
|
|
||||||
|
// Adresse de l'entrepôt
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits à stocker dans cet entrepôt venant de la classe en dessous
|
||||||
|
public List<CreateWarehouseProductDto>? Products { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO pour associer un produit à un entrepôt
|
||||||
|
public class CreateWarehouseProductDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Quantité du produit dans l'entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,43 @@
|
|||||||
namespace API.DTO.Warehouse.Request;
|
namespace API.DTO.Warehouse.Request
|
||||||
|
|
||||||
public class UpdateWarehouseDto
|
|
||||||
{
|
{
|
||||||
public int Id {get; set;}
|
// DTO pour mettre à jour un entrepôt
|
||||||
public string Name {get; set;}
|
public class UpdateWarehouseDto
|
||||||
public int MaxWeight {get; set;}
|
{
|
||||||
public int Current {get; set;}
|
// Identifiant de l'entrepôt à mettre à jour
|
||||||
public int MinWeight {get; set;}
|
public int Id { get; set; }
|
||||||
public string Adress { get; set; }
|
|
||||||
public int ZipCode { get; set; }
|
// Nom de l'entrepôt
|
||||||
public string City { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
// Poids maximal que l'entrepôt peut contenir
|
||||||
|
public int MaxWeight { get; set; }
|
||||||
|
|
||||||
|
// Poids actuel stocké
|
||||||
|
public int Current { get; set; }
|
||||||
|
|
||||||
|
// Poids minimal souhaité
|
||||||
|
public int MinWeight { get; set; }
|
||||||
|
|
||||||
|
// Adresse de l'entrepôt
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits à mettre à jour dans cet entrepôt
|
||||||
|
public List<UpdateWarehouseProductDto>? Products { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO pour mettre à jour la quantité d'un produit dans un entrepôt
|
||||||
|
public class UpdateWarehouseProductDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Nouvelle quantité du produit dans l'entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,46 @@
|
|||||||
namespace API.DTO.Warehouse.Response;
|
namespace API.DTO.Warehouse.Response
|
||||||
|
|
||||||
public class GetWarehouseDto
|
|
||||||
{
|
{
|
||||||
public int Id {get; set;}
|
// DTO pour la lecture d'un entrepôt
|
||||||
public string Name {get; set;}
|
public class GetWarehouseDto
|
||||||
public int MaxWeight {get; set;}
|
{
|
||||||
public int Current {get; set;}
|
// Identifiant de l'entrepôt
|
||||||
public int MinWeight {get; set;}
|
public int Id { get; set; }
|
||||||
public string Adress { get; set; }
|
|
||||||
public int ZipCode { get; set; }
|
// Nom de l'entrepôt
|
||||||
public string City { get; set; }
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
// Poids maximal que l'entrepôt peut contenir
|
||||||
|
public int MaxWeight { get; set; }
|
||||||
|
|
||||||
|
// Poids actuellement stocké
|
||||||
|
public int Current { get; set; }
|
||||||
|
|
||||||
|
// Poids minimal souhaité
|
||||||
|
public int MinWeight { get; set; }
|
||||||
|
|
||||||
|
// Adresse de l'entrepôt
|
||||||
|
public string? Adress { get; set; }
|
||||||
|
|
||||||
|
// Code postal
|
||||||
|
public string? ZipCode { get; set; }
|
||||||
|
|
||||||
|
// Ville
|
||||||
|
public string? City { get; set; }
|
||||||
|
|
||||||
|
// Liste des produits stockés dans l'entrepôt
|
||||||
|
public List<WarehouseProductDto>? Products { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// DTO pour la lecture d'un produit dans un entrepôt
|
||||||
|
public class WarehouseProductDto
|
||||||
|
{
|
||||||
|
// Identifiant du produit
|
||||||
|
public int ProductId { get; set; }
|
||||||
|
|
||||||
|
// Nom du produit
|
||||||
|
public string? ProductName { get; set; }
|
||||||
|
|
||||||
|
// Quantité du produit dans l'entrepôt
|
||||||
|
public int Quantity { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
using API.DTO.Brand.Request;
|
|
||||||
using API.DTO.Brand.Response;
|
using API.DTO.Brand.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Brand.Request;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
namespace PyroFetes.Endpoints.Brand;
|
||||||
|
|
||||||
@@ -8,8 +8,7 @@ public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/brands");
|
Post("/brands");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/brands/{@id}", x => new { x.Id });
|
Delete("/brands/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/brands");
|
Get("/brands");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<G
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/brands/{@id}", x => new { x.Id });
|
Get("/brands/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using API.DTO.Brand.Request;
|
|
||||||
using API.DTO.Brand.Response;
|
using API.DTO.Brand.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using PyroFetes.DTO.Brand.Request;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
namespace PyroFetes.Endpoints.Brand;
|
||||||
|
|
||||||
@@ -8,8 +8,7 @@ public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/brands");
|
Put("/brands/{Id}");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/classifications");
|
Post("/classifications");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/classifications/{@id}", x => new { x.Id });
|
Delete("/classifications/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/classifications");
|
Get("/classifications");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ public class GetClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) :E
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/classifications/{@id}", x => new { x.Id });
|
Get("/classifications/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetClassificationRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetClassificationRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/classifications");
|
Put("/classifications");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
using API.DTO.Color.Request;
|
|
||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
|
||||||
|
|
||||||
public class CreateColorEndpoint(AppDbContext appDbContext) : Endpoint<CreateColorDto, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/color/create");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateColorDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color color = new()
|
|
||||||
{
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
appDbContext.Colors.Add(color);
|
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine("Added Color");
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = color.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
34
PyroFetes/Endpoints/Color/CreateColorEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Color/CreateColorEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using API.DTO.Color.Request;
|
||||||
|
using API.DTO.Color.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Color;
|
||||||
|
|
||||||
|
public class CreateColorEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint<CreateColorDto, GetColorDto> //Instanciation d'une connexion à la bdd dans un endpoint, utilise l'élément de requête CreateColorDto et l'élement de réponse GetColorDto
|
||||||
|
{
|
||||||
|
public override void Configure() //Configuration de l'endpoint
|
||||||
|
{
|
||||||
|
Post("/colors"); //Création d'un endpoint pour créer une couleur avec les données de CreateColorDto
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateColorDto req, CancellationToken ct) //La méthode HandleAsync est appelée lorsqu'une requête est envoyée à l'endpoint
|
||||||
|
{
|
||||||
|
PyroFetes.Models.Color color = new()
|
||||||
|
{
|
||||||
|
Label = req.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
pyroFetesDbContext.Colors.Add(color);
|
||||||
|
await pyroFetesDbContext.SaveChangesAsync(ct);
|
||||||
|
Console.WriteLine("Added Color");
|
||||||
|
|
||||||
|
GetColorDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = color.Id,
|
||||||
|
Label = req.Label,
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,24 +1,23 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
namespace PyroFetes.Endpoints.Color;
|
||||||
|
|
||||||
public class DeleteColorRequest
|
public class DeleteColorRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteColorEndpoint(AppDbContext appDbContext) : Endpoint<DeleteColorRequest>
|
public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteColorRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/colors/{@id}", x => new { x.Id });
|
Delete("/colors/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Color? colorToDelete = await appDbContext
|
Models.Color? colorToDelete = await pyrofetesdbcontext
|
||||||
.Colors
|
.Colors
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -29,8 +28,8 @@ public class DeleteColorEndpoint(AppDbContext appDbContext) : Endpoint<DeleteCol
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appDbContext.Colors.Remove(colorToDelete);
|
pyrofetesdbcontext.Colors.Remove(colorToDelete);
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,18 @@ using API.DTO.Color.Response;
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
namespace PyroFetes.Endpoints.Color;
|
||||||
|
|
||||||
public class GetAllColorsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetColorDto>>
|
public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetColorDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/colors");
|
Get("/colors");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetColorDto> responseDto = await appDbContext.Colors
|
List<GetColorDto> responseDto = await pyrofetesdbcontext.Colors
|
||||||
.Select(a => new GetColorDto
|
.Select(a => new GetColorDto
|
||||||
{
|
{
|
||||||
Id = a.Id,
|
Id = a.Id,
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
using API.DTO.Color.Response;
|
using API.DTO.Color.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
namespace PyroFetes.Endpoints.Color;
|
||||||
|
|
||||||
public class GetColorRequest
|
public class GetColorRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetColorEndpoint(AppDbContext appDbContext) : Endpoint<GetColorRequest, GetColorDto>
|
public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetColorRequest, GetColorDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/colors/{@id}", x => new { x.Id});
|
Get("/colors/{@id}", x => new { x.Id});
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Color? color = await appDbContext
|
Models.Color? color = await pyrofetesdbcontext
|
||||||
.Colors
|
.Colors
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
using API.DTO.Color.Request;
|
using API.DTO.Color.Request;
|
||||||
using API.DTO.Color.Response;
|
using API.DTO.Color.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Color;
|
namespace PyroFetes.Endpoints.Color;
|
||||||
|
|
||||||
public class UpdateColorEndpoint(AppDbContext appDbContext) : Endpoint<UpdateColorDto, GetColorDto>
|
public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateColorDto, GetColorDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/colors/{@id}", x => new { x.Id });
|
Put("/colors/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Color? colorToEdit = await appDbContext
|
Models.Color? colorToEdit = await pyrofetesdbcontext
|
||||||
.Colors
|
.Colors
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ public class UpdateColorEndpoint(AppDbContext appDbContext) : Endpoint<UpdateCol
|
|||||||
|
|
||||||
}
|
}
|
||||||
colorToEdit.Label = req.Label;
|
colorToEdit.Label = req.Label;
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
GetColorDto responseDto = new()
|
||||||
{
|
{
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using API.DTO.Effect.Request;
|
using API.DTO.Effect.Request;
|
||||||
using API.DTO.Effect.Response;
|
using API.DTO.Effect.Response;
|
||||||
|
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
namespace API.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class CreateEffectEndpoint(AppDbContext appDbContext) : Endpoint<CreateEffectDto, GetEffectDto>
|
namespace PyroFetes.Endpoints.Effect;
|
||||||
|
|
||||||
|
public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateEffectDto, GetEffectDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/effect/create");
|
Post("/effects");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct)
|
||||||
@@ -19,8 +18,8 @@ public class CreateEffectEndpoint(AppDbContext appDbContext) : Endpoint<CreateEf
|
|||||||
Label = req.Label,
|
Label = req.Label,
|
||||||
};
|
};
|
||||||
|
|
||||||
appDbContext.Effects.Add(effect);
|
pyrofetesdbcontext.Effects.Add(effect);
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
Console.WriteLine("Effect added");
|
Console.WriteLine("Effect added");
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
GetEffectDto responseDto = new()
|
||||||
@@ -1,23 +1,22 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
namespace PyroFetes.Endpoints.Effect;
|
||||||
|
|
||||||
public class DeleteEffectRequest
|
public class DeleteEffectRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
public class DeleteEffectEndpoint(AppDbContext appDbContext) : Endpoint<DeleteEffectRequest>
|
public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteEffectRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/effects/{@id}", x => new { x.Id });
|
Delete("/effects/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Effect? effectToDelete = await appDbContext
|
Models.Effect? effectToDelete = await pyrofetesdbcontext
|
||||||
.Effects
|
.Effects
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -28,8 +27,8 @@ public class DeleteEffectEndpoint(AppDbContext appDbContext) : Endpoint<DeleteEf
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appDbContext.Effects.Remove(effectToDelete);
|
pyrofetesdbcontext.Effects.Remove(effectToDelete);
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
@@ -2,19 +2,18 @@ using API.DTO.Effect.Response;
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
namespace PyroFetes.Endpoints.Effect;
|
||||||
|
|
||||||
public class GetAllEffectsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetEffectDto>>
|
public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetEffectDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/effects");
|
Get("/effects");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetEffectDto> responseDto = await appDbContext.Effects
|
List<GetEffectDto> responseDto = await pyrofetesdbcontext.Effects
|
||||||
.Select(a => new GetEffectDto
|
.Select(a => new GetEffectDto
|
||||||
{
|
{
|
||||||
Id = a.Id,
|
Id = a.Id,
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
using API.DTO.Effect.Response;
|
using API.DTO.Effect.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
namespace PyroFetes.Endpoints.Effect;
|
||||||
|
|
||||||
public class GetEffectRequest
|
public class GetEffectRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetEffectEndpoint(AppDbContext appDbContext) : Endpoint<GetEffectRequest, GetEffectDto>
|
public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetEffectRequest, GetEffectDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/effect/{@id}", x => new { x.Id });
|
Get("/effects/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Effect? effect = await appDbContext
|
Models.Effect? effect = await pyrofetesdbcontext
|
||||||
.Effects
|
.Effects
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
using API.DTO.Effect.Request;
|
using API.DTO.Effect.Request;
|
||||||
using API.DTO.Effect.Response;
|
using API.DTO.Effect.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Effect;
|
namespace PyroFetes.Endpoints.Effect;
|
||||||
|
|
||||||
public class UpdateEffectEndpoint(AppDbContext appDbContext) : Endpoint<UpdateEffectDto, GetEffectDto>
|
public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateEffectDto, GetEffectDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/effect/{@id}", x => new { x.Id });
|
Put("/effects/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Effect? effectToEdit = await appDbContext
|
Models.Effect? effectToEdit = await pyrofetesdbcontext
|
||||||
.Effects
|
.Effects
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -28,7 +26,7 @@ public class UpdateEffectEndpoint(AppDbContext appDbContext) : Endpoint<UpdateEf
|
|||||||
|
|
||||||
}
|
}
|
||||||
effectToEdit.Label = req.Label;
|
effectToEdit.Label = req.Label;
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
GetEffectDto responseDto = new()
|
||||||
{
|
{
|
||||||
53
PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs
Normal file
53
PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PasswordGenerator;
|
||||||
|
using PyroFetes.DTO.Login.Request;
|
||||||
|
using PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint<CreateLoginDto, GetLoginDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/logins");
|
||||||
|
//Roles("Admin");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CreateLoginDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
bool exists = await database.Users.AnyAsync(x => x.Name == req.Name, ct);
|
||||||
|
if (exists)
|
||||||
|
{
|
||||||
|
AddError("Ce nom d'utilisateur est déjà utilisé.");
|
||||||
|
await Send.ErrorsAsync(400, ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||||
|
|
||||||
|
Models.User login = new Models.User()
|
||||||
|
{
|
||||||
|
Name = req.Name,
|
||||||
|
Email = req.Email,
|
||||||
|
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
||||||
|
Salt = salt,
|
||||||
|
|
||||||
|
Fonction = string.IsNullOrEmpty(req.Fonction) ? "User" : req.Fonction
|
||||||
|
};
|
||||||
|
|
||||||
|
database.Users.Add(login);
|
||||||
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetLoginDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = login.Id,
|
||||||
|
Name = login.Name,
|
||||||
|
Email = login.Email,
|
||||||
|
Fonction = login.Fonction
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
34
PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs
Normal file
34
PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class DeleteLoginRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DeleteLoginEndpoint(PyroFetesDbContext database) : Endpoint<DeleteLoginRequest>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Delete("/logins/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.User? login = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||||
|
|
||||||
|
if (login == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
database.Users.Remove(login);
|
||||||
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
await Send.NoContentAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
29
PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs
Normal file
29
PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class GetAllLoginEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetLoginDto>>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/logins");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
List<GetLoginDto> logins = await database.Users
|
||||||
|
.Select(login => new GetLoginDto()
|
||||||
|
{
|
||||||
|
Id = login.Id,
|
||||||
|
Name = login.Name,
|
||||||
|
Password = login.Password,
|
||||||
|
Fonction = login.Fonction
|
||||||
|
})
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
await Send.OkAsync(logins, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
40
PyroFetes/Endpoints/Login/GetLoginEndpoint.cs
Normal file
40
PyroFetes/Endpoints/Login/GetLoginEndpoint.cs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class GetLoginRequest
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GetLoginEndpoint(PyroFetesDbContext database) : Endpoint<GetLoginRequest, GetLoginDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Get("/logins/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.User? login = await database.Users
|
||||||
|
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||||
|
|
||||||
|
if (login == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GetLoginDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = login.Id,
|
||||||
|
Name = login.Name,
|
||||||
|
Fonction = login.Fonction
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs
Normal file
43
PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PasswordGenerator;
|
||||||
|
using PyroFetes.DTO.Login.Request;
|
||||||
|
using PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class UpdateLoginEndpoint(PyroFetesDbContext database) : Endpoint<UpdateLoginDto, GetLoginDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Put("/logins/{@Id}", x => new {x.Id});
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(UpdateLoginDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.User? login = await database.Users.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
||||||
|
|
||||||
|
if (login == null)
|
||||||
|
{
|
||||||
|
await Send.NotFoundAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
||||||
|
|
||||||
|
login.Name = req.Name;
|
||||||
|
login.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt);
|
||||||
|
login.Salt = salt;
|
||||||
|
await database.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
GetLoginDto responseDto = new()
|
||||||
|
{
|
||||||
|
Id = login.Id,
|
||||||
|
Name = login.Name,
|
||||||
|
Fonction = login.Fonction
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
48
PyroFetes/Endpoints/Login/UserLoginEndpoint.cs
Normal file
48
PyroFetes/Endpoints/Login/UserLoginEndpoint.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using FastEndpoints;
|
||||||
|
using FastEndpoints.Security;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Login.Request;
|
||||||
|
using PyroFetes.DTO.Login.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Login;
|
||||||
|
|
||||||
|
public class UserLoginEndpoint(PyroFetesDbContext database) : Endpoint<ConnectLoginDto, GetLoginConnectDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/login");
|
||||||
|
AllowAnonymous();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(ConnectLoginDto req, CancellationToken ct)
|
||||||
|
{
|
||||||
|
Models.User? login = await database.Users.SingleOrDefaultAsync(x => x.Name == req.Name, ct);
|
||||||
|
|
||||||
|
if (login == null)
|
||||||
|
{
|
||||||
|
await Send.UnauthorizedAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (BCrypt.Net.BCrypt.Verify(req.Password + login.Salt, login.Password))
|
||||||
|
{
|
||||||
|
string jwtToken = JwtBearer.CreateToken(
|
||||||
|
o =>
|
||||||
|
{
|
||||||
|
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||||
|
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||||
|
if (login.Fonction != null) o.User.Roles.Add(login.Fonction);
|
||||||
|
o.User.Claims.Add(("Username", login.Name)!);
|
||||||
|
o.User["UserId"] = "001";
|
||||||
|
});
|
||||||
|
|
||||||
|
GetLoginConnectDto responseDto = new()
|
||||||
|
{
|
||||||
|
Token = jwtToken
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
else await Send.UnauthorizedAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,34 +1,34 @@
|
|||||||
using API.DTO.Material.Request;
|
using API.DTO.Material.Request;
|
||||||
using API.DTO.Material.Response;
|
using API.DTO.Material.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
namespace API.Endpoints.Material;
|
|
||||||
|
|
||||||
public class CreateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
namespace PyroFetes.Endpoints.Material;
|
||||||
|
|
||||||
|
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/material/create");
|
Post("/materials");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Material quantity = new()
|
Models.Material quantity = new()
|
||||||
{
|
{
|
||||||
Name = req.Name,
|
Name = req.Label,
|
||||||
Quantity = req.Quantity,
|
Quantity = req.Quantity,
|
||||||
WarehouseId = req.WarehouseId,
|
WarehouseId = req.WarehouseId,
|
||||||
};
|
};
|
||||||
|
|
||||||
appDbContext.Materials.Add(quantity);
|
pyrofetesdbcontext.Materials.Add(quantity);
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
Console.WriteLine("Material added");
|
Console.WriteLine("Material added");
|
||||||
|
|
||||||
GetMaterialDto responseDto = new()
|
GetMaterialDto responseDto = new()
|
||||||
{
|
{
|
||||||
Id = quantity.Id,
|
Id = quantity.Id,
|
||||||
WarehouseId = quantity.WarehouseId,
|
WarehouseId = quantity.WarehouseId,
|
||||||
Name = req.Name,
|
Label = req.Label,
|
||||||
};
|
};
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(responseDto, ct);
|
||||||
@@ -1,22 +1,21 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Material;
|
namespace PyroFetes.Endpoints.Material;
|
||||||
public class DeleteMaterialRequest
|
public class DeleteMaterialRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
public class DeleteMaterialEndpoint(AppDbContext appDbContext) : Endpoint<DeleteMaterialRequest>
|
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/materials/{@id}", x => new { x.Id });
|
Delete("/materials/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Material? materialToDelete = await appDbContext
|
Models.Material? materialToDelete = await pyrofetesdbcontext
|
||||||
.Materials
|
.Materials
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -27,8 +26,8 @@ public class DeleteMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Delete
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
appDbContext.Materials.Remove(materialToDelete);
|
pyrofetesdbcontext.Materials.Remove(materialToDelete);
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
@@ -2,23 +2,22 @@ using API.DTO.Material.Response;
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Material;
|
namespace PyroFetes.Endpoints.Material;
|
||||||
|
|
||||||
public class GetAllMaterialsEndpoint(AppDbContext appDbContext) : EndpointWithoutRequest<List<GetMaterialDto>>
|
public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMaterialDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/material");
|
Get("/materials");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetMaterialDto> responseDto = await appDbContext.Materials
|
List<GetMaterialDto> responseDto = await pyrofetesdbcontext.Materials
|
||||||
.Select(a => new GetMaterialDto
|
.Select(a => new GetMaterialDto
|
||||||
{
|
{
|
||||||
Id = a.Id,
|
Id = a.Id,
|
||||||
Name = a.Name,
|
Label = a.Name,
|
||||||
Quantity = a.Quantity,
|
Quantity = a.Quantity,
|
||||||
WarehouseId = a.WarehouseId,
|
WarehouseId = a.WarehouseId,
|
||||||
}
|
}
|
||||||
@@ -1,26 +1,24 @@
|
|||||||
using API.DTO.Material.Response;
|
using API.DTO.Material.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Authentication;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Material;
|
namespace PyroFetes.Endpoints.Material;
|
||||||
|
|
||||||
public class GetMaterialRequest
|
public class GetMaterialRequest
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint<GetMaterialRequest, GetMaterialDto>
|
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/material/{@id}", x => new { x.Id });
|
Get("/materials/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Material? material = await appDbContext
|
Models.Material? material = await pyrofetesdbcontext
|
||||||
.Materials
|
.Materials
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -34,7 +32,7 @@ public class GetMaterialEndpoint(AppDbContext appDbContext) : Endpoint<GetMateri
|
|||||||
GetMaterialDto responseDto = new()
|
GetMaterialDto responseDto = new()
|
||||||
{
|
{
|
||||||
Id = material.Id,
|
Id = material.Id,
|
||||||
Name = material.Name,
|
Label = material.Name,
|
||||||
WarehouseId = material.WarehouseId,
|
WarehouseId = material.WarehouseId,
|
||||||
};
|
};
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(responseDto, ct);
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
using API.DTO.Material.Request;
|
using API.DTO.Material.Request;
|
||||||
using API.DTO.Material.Response;
|
using API.DTO.Material.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.AspNetCore.Server.Kestrel;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace API.Endpoints.Material;
|
namespace PyroFetes.Endpoints.Material;
|
||||||
|
|
||||||
public class UpdateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
|
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/material/{@id}", x => new { x.Id });
|
Put("/materials/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Material? materialToEdit = await appDbContext
|
Models.Material? materialToEdit = await pyrofetesdbcontext
|
||||||
.Materials
|
.Materials
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
@@ -27,14 +25,14 @@ public class UpdateMaterialEndpoint(AppDbContext appDbContext) : Endpoint<Update
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
materialToEdit.Name = req.Name;
|
materialToEdit.Name = req.Label;
|
||||||
materialToEdit.WarehouseId = req.WarehouseId;
|
materialToEdit.WarehouseId = req.WarehouseId;
|
||||||
await appDbContext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
GetMaterialDto responseDto = new()
|
GetMaterialDto responseDto = new()
|
||||||
{
|
{
|
||||||
Id = req.Id,
|
Id = req.Id,
|
||||||
Name = req.Name,
|
Label = req.Label,
|
||||||
WarehouseId = req.WarehouseId,
|
WarehouseId = req.WarehouseId,
|
||||||
};
|
};
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(responseDto, ct);
|
||||||
@@ -8,8 +8,7 @@ public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/movements");
|
Post("/movements");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/Movements/{@id}", x => new { x.Id });
|
Delete("/Movements/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/movements");
|
Get("/movements");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoin
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/movements/{@id}", x => new { x.Id });
|
Get("/movements/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/movements");
|
Put("/movements");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -1,44 +1,80 @@
|
|||||||
using FastEndpoints;
|
using PyroFetes.DTO.Product.Request;
|
||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
namespace PyroFetes.Endpoints.Product;
|
||||||
|
|
||||||
public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateProductDto, GetProductDto>
|
public class CreateProductEndpoint(PyroFetesDbContext db)
|
||||||
|
: Endpoint<CreateProductDto, GetProductDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/products");
|
Post("/products");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateProductDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateProductDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Product product = new ()
|
var product = new Models.Product
|
||||||
{
|
{
|
||||||
References = req.References,
|
Reference = req.Reference,
|
||||||
Name = req.Name!,
|
Name = req.Name!,
|
||||||
Duration = req.Duration,
|
Duration = req.Duration,
|
||||||
Caliber = req.Caliber,
|
Caliber = req.Caliber,
|
||||||
ApprovalNumber = req.ApprovalNumber,
|
ApprovalNumber = req.ApprovalNumber,
|
||||||
Weight = req.Weight,
|
Weight = req.Weight,
|
||||||
Nec = req.Nec,
|
Nec = req.Nec,
|
||||||
SellingPrice = req.SellingPrice,
|
|
||||||
Image = req.Image!,
|
Image = req.Image!,
|
||||||
Link = req.Link!,
|
Link = req.Link!,
|
||||||
ProductCategoryId = req.ProductCategoryId,
|
ProductCategoryId = req.ProductCategoryId,
|
||||||
ClassificationId = req.ClassificationId
|
ClassificationId = req.ClassificationId
|
||||||
};
|
};
|
||||||
|
|
||||||
pyrofetesdbcontext.Products.Add(product);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Product créé avec succès !");
|
|
||||||
|
|
||||||
GetProductDto responseDto = new ()
|
db.Products.Add(product);
|
||||||
|
await db.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,
|
Id = product.Id,
|
||||||
Reference = req.References,
|
Reference = req.Reference,
|
||||||
Name = req.Name,
|
Name = req.Name,
|
||||||
Duration = req.Duration,
|
Duration = req.Duration,
|
||||||
Caliber = req.Caliber,
|
Caliber = req.Caliber,
|
||||||
@@ -49,9 +85,20 @@ public class CreateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
|
|||||||
Image = req.Image,
|
Image = req.Image,
|
||||||
Link = req.Link,
|
Link = req.Link,
|
||||||
ProductCategoryId = req.ProductCategoryId,
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
namespace PyroFetes.Endpoints.Product;
|
||||||
|
|
||||||
@@ -8,29 +9,49 @@ public class DeleteProductRequest
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteProductRequest>
|
public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint<DeleteProductRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/products/{@id}", x => new { x.Id });
|
Delete("/products/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Product? productToDelete = await pyrofetesdbcontext
|
// Récupérer le produit
|
||||||
.Products
|
var productToDelete = await db.Products
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
||||||
|
|
||||||
if (productToDelete == null)
|
if (productToDelete is null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
|
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pyrofetesdbcontext.Products.Remove(productToDelete);
|
// Supprimer les liaisons Price
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
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);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,61 @@
|
|||||||
using FastEndpoints;
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.Product.Response;
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
namespace PyroFetes.Endpoints.Product;
|
||||||
|
|
||||||
public class GetAllProductsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductDto>>
|
public class GetAllProductsEndpoint(PyroFetesDbContext db)
|
||||||
|
: EndpointWithoutRequest<List<GetProductDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/products");
|
Get("/products");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetProductDto> responseDto = await pyrofetesdbcontext.Products
|
// Inclure toutes les relations nécessaires : Prices + WarehouseProducts + Warehouse
|
||||||
.Select(p => new GetProductDto()
|
var products = await db.Products
|
||||||
{
|
.Include(p => p.Prices)
|
||||||
Id = p.Id,
|
.Include(p => p.WarehouseProducts)!
|
||||||
Reference = p.References,
|
.ThenInclude(wp => wp.Warehouse)
|
||||||
Name = p.Name,
|
.ToListAsync(ct);
|
||||||
Duration = p.Duration,
|
|
||||||
Caliber = p.Caliber,
|
var responseDto = products.Select(p => new GetProductDto
|
||||||
ApprovalNumber = p.ApprovalNumber,
|
{
|
||||||
Weight = p.Weight,
|
Id = p.Id,
|
||||||
Nec = p.Nec,
|
// Le modèle Product contient "Reference" (string) — pas "References" (int)
|
||||||
SellingPrice = p.SellingPrice,
|
Reference = p.Reference,
|
||||||
Image = p.Image,
|
Name = p.Name,
|
||||||
Link = p.Link,
|
Duration = p.Duration,
|
||||||
ClassificationId = p.ClassificationId,
|
Caliber = p.Caliber,
|
||||||
ClassificationLabel = p.Classification!.Label,
|
ApprovalNumber = p.ApprovalNumber,
|
||||||
ProductCategoryId = p.ProductCategoryId,
|
Weight = p.Weight,
|
||||||
ProductCategoryLabel = p.ProductCategory!.Label,
|
Nec = p.Nec,
|
||||||
}
|
// Le prix de vente n’est pas dans Product, on le récupère via Prices
|
||||||
).ToListAsync(ct);
|
SellingPrice = p.Prices.FirstOrDefault()?.SellingPrice ?? 0,
|
||||||
|
Image = p.Image,
|
||||||
|
Link = p.Link,
|
||||||
|
ClassificationId = p.ClassificationId,
|
||||||
|
ProductCategoryId = p.ProductCategoryId,
|
||||||
|
|
||||||
|
// 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 liés 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);
|
await Send.OkAsync(responseDto, ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using FastEndpoints;
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using PyroFetes.DTO.Product.Response;
|
using PyroFetes.DTO.Product.Request;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
namespace PyroFetes.Endpoints.Product;
|
||||||
|
|
||||||
@@ -9,20 +11,22 @@ public class GetProductRequest
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class GetProductEndpoint(PyroFetesDbContext db)
|
||||||
public class GetProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetProductRequest, GetProductDto>
|
: Endpoint<GetProductRequest, GetProductDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/product/{@id}", x => new { x.Id });
|
Get("/products/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Product? product = await pyrofetesdbcontext
|
// Inclure toutes les relations : Prices + WarehouseProducts + Warehouse
|
||||||
.Products.Include(product => product.Classification).Include(product => product.ProductCategory)
|
var product = await db.Products
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
|
.Include(p => p.Prices)
|
||||||
|
.Include(p => p.WarehouseProducts)!
|
||||||
|
.ThenInclude(wp => wp.Warehouse)
|
||||||
|
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
||||||
|
|
||||||
if (product == null)
|
if (product == null)
|
||||||
{
|
{
|
||||||
@@ -31,23 +35,42 @@ public class GetProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetProductDto responseDto = new()
|
var responseDto = new GetProductDto
|
||||||
{
|
{
|
||||||
Id = product.Id,
|
Id = product.Id,
|
||||||
Reference = product.References,
|
|
||||||
|
// Le modèle Product contient "Reference" (string), pas "References" (int)
|
||||||
|
Reference = product.Reference,
|
||||||
|
|
||||||
Name = product.Name,
|
Name = product.Name,
|
||||||
Duration = product.Duration,
|
Duration = product.Duration,
|
||||||
Caliber = product.Caliber,
|
Caliber = product.Caliber,
|
||||||
ApprovalNumber = product.ApprovalNumber,
|
ApprovalNumber = product.ApprovalNumber,
|
||||||
Weight = product.Weight,
|
Weight = product.Weight,
|
||||||
Nec = product.Nec,
|
Nec = product.Nec,
|
||||||
SellingPrice = product.SellingPrice,
|
|
||||||
|
// Le prix de vente n’est pas dans Product → récupéré via Price
|
||||||
|
SellingPrice = product.Prices.FirstOrDefault()?.SellingPrice ?? 0,
|
||||||
|
|
||||||
Image = product.Image,
|
Image = product.Image,
|
||||||
Link = product.Link,
|
Link = product.Link,
|
||||||
ClassificationId = product.ClassificationId,
|
ClassificationId = product.ClassificationId,
|
||||||
ClassificationLabel = product.Classification!.Label,
|
ProductCategoryId = product.ProductCategoryId,
|
||||||
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);
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
|||||||
@@ -1,58 +1,100 @@
|
|||||||
using FastEndpoints;
|
using PyroFetes.DTO.Product.Request;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
using PyroFetes.DTO.Product.Response;
|
||||||
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
namespace PyroFetes.Endpoints.Product;
|
||||||
|
|
||||||
public class UpdateProductEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<UpdateProductDto, GetProductDto>
|
public class UpdateProductEndpoint(PyroFetesDbContext db)
|
||||||
|
: Endpoint<UpdateProductDto, GetProductDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/api/products/{@id}", x => new { x.Id });
|
Put("/products/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Product? productToEdit = await pyrofetesdbcontext
|
var product = await db.Products
|
||||||
.Products
|
.Include(p => p.Prices)
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, cancellationToken: ct);
|
.Include(p => p.WarehouseProducts)
|
||||||
|
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
||||||
|
|
||||||
if (productToEdit == null)
|
if (product is null)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
productToEdit.References = req.Reference;
|
product.Reference = req.Reference;
|
||||||
productToEdit.Name = req.Name;
|
product.Name = req.Name;
|
||||||
productToEdit.Duration = req.Duration;
|
product.Duration = req.Duration;
|
||||||
productToEdit.Caliber = req.Caliber;
|
product.Caliber = req.Caliber;
|
||||||
productToEdit.ApprovalNumber = req.ApprovalNumber;
|
product.ApprovalNumber = req.ApprovalNumber;
|
||||||
productToEdit.Weight = req.Weight;
|
product.Weight = req.Weight;
|
||||||
productToEdit.Nec = req.Nec;
|
product.Nec = req.Nec;
|
||||||
productToEdit.SellingPrice = req.SellingPrice;
|
product.Image = req.Image;
|
||||||
productToEdit.Image = req.Image;
|
product.Link = req.Link;
|
||||||
productToEdit.Link = req.Link;
|
product.ClassificationId = req.ClassificationId;
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
product.ProductCategoryId = req.ProductCategoryId;
|
||||||
|
|
||||||
GetProductDto responseDto = new()
|
db.Prices.RemoveRange(product.Prices);
|
||||||
|
foreach (var s in req.Suppliers)
|
||||||
{
|
{
|
||||||
Id = req.Id,
|
db.Prices.Add(new Price
|
||||||
Reference = req.Reference,
|
{
|
||||||
|
ProductId = product.Id,
|
||||||
|
SupplierId = s.SupplierId,
|
||||||
|
SellingPrice = s.SellingPrice
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
var response = new GetProductDto
|
||||||
|
{
|
||||||
|
Id = product.Id,
|
||||||
|
Reference = req.Reference,
|
||||||
Name = req.Name,
|
Name = req.Name,
|
||||||
Duration = req.Duration,
|
Duration = req.Duration,
|
||||||
Caliber = req.Caliber,
|
Caliber = req.Caliber,
|
||||||
ApprovalNumber = req.ApprovalNumber,
|
ApprovalNumber = req.ApprovalNumber,
|
||||||
Weight = req.Weight,
|
Weight = req.Weight,
|
||||||
Nec = req.Nec,
|
Nec = req.Nec,
|
||||||
SellingPrice = req.SellingPrice,
|
SellingPrice = req.Suppliers.FirstOrDefault()?.SellingPrice ?? 0,
|
||||||
Image = req.Image,
|
Image = req.Image,
|
||||||
Link = req.Link
|
Link = req.Link,
|
||||||
|
ClassificationId = req.ClassificationId,
|
||||||
|
ProductCategoryId = req.ProductCategoryId,
|
||||||
|
|
||||||
|
Suppliers = req.Suppliers.Select(s => new ProductSupplierPriceDto
|
||||||
|
{
|
||||||
|
SupplierId = s.SupplierId,
|
||||||
|
SellingPrice = s.SellingPrice
|
||||||
|
}).ToList(),
|
||||||
|
|
||||||
|
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);
|
await Send.OkAsync(response, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ public class CreateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/productcategories");
|
Post("/productcategories");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateProductCategoryDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateProductCategoryDto req, CancellationToken ct)
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ public class DeleteProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/productcategories/{@id}", x => new { x.Id });
|
Delete("/productcategories/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteProductCategoryRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteProductCategoryRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -4,12 +4,11 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
namespace PyroFetes.Endpoints.ProductCategory;
|
||||||
|
|
||||||
public class GetAllProductCategoriesEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductCategoryDto>>
|
public class GetAllProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductCategoryDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/productcategories");
|
Get("/productcategories");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
@@ -14,8 +14,7 @@ public class GetProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) :
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/productcategory/{@id}", x => new { x.Id });
|
Get("/productcategory/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetProductCategoryRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetProductCategoryRequest req, CancellationToken ct)
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ public class UpdateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/api/productcategory/{@id}", x => new { x.Id });
|
Put("/productcategory/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateProductCategoryDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateProductCategoryDto req, CancellationToken ct)
|
||||||
|
|||||||
74
PyroFetes/Endpoints/Refresh/RefreshTokenEndpoint.cs
Normal file
74
PyroFetes/Endpoints/Refresh/RefreshTokenEndpoint.cs
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using FastEndpoints;
|
||||||
|
using FastEndpoints.Security;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.DTO.Refrresh.Response;
|
||||||
|
|
||||||
|
namespace PyroFetes.Endpoints.Refresh;
|
||||||
|
|
||||||
|
public class RefreshTokenEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<GetRefreshDto>
|
||||||
|
{
|
||||||
|
public override void Configure()
|
||||||
|
{
|
||||||
|
Post("/refresh");
|
||||||
|
// [Authorize] est géré ici avec les rôles
|
||||||
|
Roles("Admin", "User");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 1. 🚨 CORRECTION : Lire le claim 'Name' du jeton validé par le middleware
|
||||||
|
// Le claim 'Name' contient le nom d'utilisateur
|
||||||
|
string? userName = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(userName))
|
||||||
|
{
|
||||||
|
// Si le claim Name est manquant (ce qui ne devrait pas arriver)
|
||||||
|
await Send.UnauthorizedAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 🚨 CORRECTION : Utiliser le Nom (Name) pour la recherche BDD
|
||||||
|
// Assurez-vous que la propriété de l'entité est 'Name' et qu'elle est unique
|
||||||
|
var login = await database.Users.FirstOrDefaultAsync(x => x.Name == userName, ct);
|
||||||
|
if (login == null)
|
||||||
|
{
|
||||||
|
await Send.UnauthorizedAsync(ct);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Création du NOUVEAU jeton
|
||||||
|
string jwtToken = JwtBearer.CreateToken(
|
||||||
|
o =>
|
||||||
|
{
|
||||||
|
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
||||||
|
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
||||||
|
|
||||||
|
// Assurez-vous que les claims sont corrects pour Angular
|
||||||
|
if (login.Fonction != null) o.User.Roles.Add(login.Fonction);
|
||||||
|
|
||||||
|
// Ajouter le claim Name (Nom d'utilisateur)
|
||||||
|
o.User.Claims.Add((ClaimTypes.Name, login.Name)!);
|
||||||
|
|
||||||
|
// Si votre API mettait d'autres claims, ajoutez-les ici (ex: "Username")
|
||||||
|
// o.User.Claims.Add(("Username", login.Name)!);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 4. Envoi de la réponse
|
||||||
|
GetRefreshDto responseDto = new()
|
||||||
|
{
|
||||||
|
Token = jwtToken
|
||||||
|
};
|
||||||
|
|
||||||
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
await Send.UnauthorizedAsync(ct);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,22 @@
|
|||||||
using API.DTO.Supplier.Request;
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
using API.DTO.Supplier.Response;
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
namespace PyroFetes.Endpoints.Supplier;
|
||||||
|
|
||||||
public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateSupplierDto, GetSupplierDto>
|
public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
||||||
|
: Endpoint<CreateSupplierDto, GetSupplierDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/suppliers");
|
Post("/suppliers");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
// Création d'un nouvel objet Supplier
|
var supplier = new Models.Supplier
|
||||||
Models.Supplier supplier = new()
|
|
||||||
{
|
{
|
||||||
Name = req.Name,
|
Name = req.Name,
|
||||||
Email = req.Email,
|
Email = req.Email,
|
||||||
@@ -24,15 +25,27 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
ZipCode = req.ZipCode,
|
ZipCode = req.ZipCode,
|
||||||
City = req.City
|
City = req.City
|
||||||
};
|
};
|
||||||
|
|
||||||
// Ajout à la base et sauvegarde
|
|
||||||
pyrofetesdbcontext.Suppliers.Add(supplier);
|
pyrofetesdbcontext.Suppliers.Add(supplier);
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
Console.WriteLine("Fournisseur créé avec succès !");
|
|
||||||
|
|
||||||
// Préparation de la réponse
|
// Ajout des liaisons Price si produits renseignés
|
||||||
GetSupplierDto responseDto = new()
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = new GetSupplierDto
|
||||||
{
|
{
|
||||||
Id = supplier.Id,
|
Id = supplier.Id,
|
||||||
Name = supplier.Name,
|
Name = supplier.Name,
|
||||||
@@ -43,6 +56,6 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
City = supplier.City
|
City = supplier.City
|
||||||
};
|
};
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(response, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
namespace PyroFetes.Endpoints.Supplier;
|
||||||
|
|
||||||
@@ -12,25 +13,37 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/suppliers/{@id}", x => new { x.Id });
|
Delete("/suppliers/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Supplier? supplierToDelete = await pyrofetesdbcontext
|
var supplierToDelete = await pyrofetesdbcontext
|
||||||
.Suppliers
|
.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é.");
|
Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé.");
|
||||||
await Send.NotFoundAsync(ct);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
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);
|
pyrofetesdbcontext.Suppliers.Remove(supplierToDelete);
|
||||||
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
Console.WriteLine($"Fournisseur {req.Id} et ses prix liés supprimés avec succès.");
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,43 @@
|
|||||||
using API.DTO.Supplier.Response;
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
namespace PyroFetes.Endpoints.Supplier;
|
||||||
|
|
||||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetSupplierDto>>
|
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
||||||
|
: EndpointWithoutRequest<List<GetSupplierDto>>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/suppliers");
|
Get("/suppliers");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
public override async Task HandleAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
List<GetSupplierDto> responseDto = await pyrofetesdbcontext.Suppliers
|
var suppliers = await pyrofetesdbcontext.Suppliers
|
||||||
.Select(s => new GetSupplierDto
|
.Include(s => s.Prices)
|
||||||
{
|
|
||||||
Id = s.Id,
|
|
||||||
Name = s.Name!,
|
|
||||||
Email = s.Email!,
|
|
||||||
PhoneNumber = s.Phone!,
|
|
||||||
Adress = s.Address!,
|
|
||||||
ZipCode = s.ZipCode,
|
|
||||||
City = s.City!
|
|
||||||
})
|
|
||||||
.ToListAsync(ct);
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
var responseDto = suppliers.Select(s => new GetSupplierDto
|
||||||
|
{
|
||||||
|
Id = s.Id,
|
||||||
|
Name = s.Name!,
|
||||||
|
Email = s.Email!,
|
||||||
|
PhoneNumber = s.Phone!,
|
||||||
|
Adress = s.Address!,
|
||||||
|
ZipCode = s.ZipCode,
|
||||||
|
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);
|
await Send.OkAsync(responseDto, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using API.DTO.Supplier.Response;
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@@ -9,19 +10,19 @@ public class GetSupplierRequest
|
|||||||
public int Id { get; set; }
|
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()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Get("/api/suppliers/{@id}", x => new { x.Id });
|
Get("/suppliers/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Supplier? supplier = await pyrofetesdbcontext
|
var supplier = await pyrofetesdbcontext.Suppliers
|
||||||
.Suppliers
|
.Include(s => s.Prices)
|
||||||
.SingleOrDefaultAsync(s => s.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
|
||||||
|
|
||||||
if (supplier == null)
|
if (supplier == null)
|
||||||
{
|
{
|
||||||
@@ -30,7 +31,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetSupplierDto responseDto = new()
|
var responseDto = new GetSupplierDto
|
||||||
{
|
{
|
||||||
Id = supplier.Id,
|
Id = supplier.Id,
|
||||||
Name = supplier.Name!,
|
Name = supplier.Name!,
|
||||||
@@ -38,7 +39,14 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
|
|||||||
PhoneNumber = supplier.Phone!,
|
PhoneNumber = supplier.Phone!,
|
||||||
Adress = supplier.Address!,
|
Adress = supplier.Address!,
|
||||||
ZipCode = supplier.ZipCode,
|
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);
|
await Send.OkAsync(responseDto, ct);
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
using API.DTO.Supplier.Request;
|
using PyroFetes.DTO.Supplier.Request;
|
||||||
using API.DTO.Supplier.Response;
|
using PyroFetes.DTO.Supplier.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
namespace PyroFetes.Endpoints.Supplier;
|
||||||
|
|
||||||
@@ -9,24 +10,21 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Put("/api/suppliers/{@id}", x => new { x.Id });
|
Put("/suppliers/{@id}", x => new { x.Id });
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Supplier? supplierToEdit = await pyrofetesdbcontext
|
var supplierToEdit = await pyrofetesdbcontext
|
||||||
.Suppliers
|
.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);
|
await Send.NotFoundAsync(ct);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mise à jour des propriétés
|
|
||||||
supplierToEdit.Name = req.Name;
|
supplierToEdit.Name = req.Name;
|
||||||
supplierToEdit.Email = req.Email;
|
supplierToEdit.Email = req.Email;
|
||||||
supplierToEdit.Phone = req.PhoneNumber;
|
supplierToEdit.Phone = req.PhoneNumber;
|
||||||
@@ -34,9 +32,28 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
supplierToEdit.ZipCode = req.ZipCode;
|
supplierToEdit.ZipCode = req.ZipCode;
|
||||||
supplierToEdit.City = req.City;
|
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);
|
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
||||||
|
|
||||||
GetSupplierDto responseDto = new()
|
var response = new GetSupplierDto
|
||||||
{
|
{
|
||||||
Id = supplierToEdit.Id,
|
Id = supplierToEdit.Id,
|
||||||
Name = supplierToEdit.Name,
|
Name = supplierToEdit.Name,
|
||||||
@@ -47,6 +64,6 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
|
|||||||
City = supplierToEdit.City
|
City = supplierToEdit.City
|
||||||
};
|
};
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(response, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
using API.DTO.Warehouse.Request;
|
using API.DTO.Warehouse.Request;
|
||||||
using API.DTO.Warehouse.Response;
|
using API.DTO.Warehouse.Response;
|
||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
namespace PyroFetes.Endpoints.Warehouse;
|
||||||
|
|
||||||
public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateWarehouseDto, GetWarehouseDto>
|
public class CreateWarehouseEndpoint(PyroFetesDbContext db)
|
||||||
|
: Endpoint<CreateWarehouseDto, GetWarehouseDto>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Post("/api/warehouse");
|
Post("/warehouse");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct)
|
public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Warehouse warehouse = new()
|
var warehouse = new Models.Warehouse
|
||||||
{
|
{
|
||||||
Name = req.Name,
|
Name = req.Name,
|
||||||
MaxWeight = req.MaxWeight,
|
MaxWeight = req.MaxWeight,
|
||||||
@@ -24,13 +25,27 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
|||||||
ZipCode = req.ZipCode,
|
ZipCode = req.ZipCode,
|
||||||
City = req.City
|
City = req.City
|
||||||
};
|
};
|
||||||
|
|
||||||
pyrofetesdbcontext.Warehouses.Add(warehouse);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Entrepôt créé avec succès !");
|
|
||||||
|
|
||||||
GetWarehouseDto responseDto = new()
|
db.Warehouses.Add(warehouse);
|
||||||
|
await db.SaveChangesAsync(ct);
|
||||||
|
|
||||||
|
// 🔹 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
var response = new GetWarehouseDto
|
||||||
{
|
{
|
||||||
Id = warehouse.Id,
|
Id = warehouse.Id,
|
||||||
Name = warehouse.Name,
|
Name = warehouse.Name,
|
||||||
@@ -42,6 +57,6 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
|||||||
City = warehouse.City
|
City = warehouse.City
|
||||||
};
|
};
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
await Send.OkAsync(response, ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using FastEndpoints;
|
using FastEndpoints;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PyroFetes.Models;
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
namespace PyroFetes.Endpoints.Warehouse;
|
||||||
|
|
||||||
@@ -8,18 +9,17 @@ public class DeleteWarehouseRequest
|
|||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DeleteWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteWarehouseRequest>
|
public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint<DeleteWarehouseRequest>
|
||||||
{
|
{
|
||||||
public override void Configure()
|
public override void Configure()
|
||||||
{
|
{
|
||||||
Delete("/api/warehouse/{@id}", x => new { x.Id });
|
Delete("/warehouse/{id}");
|
||||||
AllowAnonymous();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)
|
public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)
|
||||||
{
|
{
|
||||||
Models.Warehouse? warehouseToDelete = await pyrofetesdbcontext
|
// On charge aussi les WarehouseProducts liés pour les supprimer proprement
|
||||||
.Warehouses
|
var warehouseToDelete = await db.Warehouses
|
||||||
|
.Include(w => w.WarehouseProducts)
|
||||||
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
|
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
|
||||||
|
|
||||||
if (warehouseToDelete == null)
|
if (warehouseToDelete == null)
|
||||||
@@ -29,9 +29,21 @@ public class DeleteWarehouseEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pyrofetesdbcontext.Warehouses.Remove(warehouseToDelete);
|
// 🔹 Suppression des relations WarehouseProduct avant l'entrepôt
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
var relatedWarehouseProducts = await db.WarehouseProducts
|
||||||
|
.Where(wp => wp.WarehouseId == req.Id)
|
||||||
|
.ToListAsync(ct);
|
||||||
|
|
||||||
|
if (relatedWarehouseProducts.Any())
|
||||||
|
{
|
||||||
|
db.WarehouseProducts.RemoveRange(relatedWarehouseProducts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🔹 Suppression de l’entrepô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);
|
await Send.NoContentAsync(ct);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user