forked from sanchezvem/PyroFetes
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
6a813fc35a | |||
a93d399942 |
@@ -1,9 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Brand.Request
|
|
||||||
{
|
|
||||||
// DTO pour créer une nouvelle marque
|
|
||||||
public class CreateBrandDto
|
|
||||||
{
|
|
||||||
// Nom de la marque
|
|
||||||
public string? Name { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Brand.Request
|
|
||||||
{
|
|
||||||
// DTO pour mettre à jour une marque existante
|
|
||||||
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,12 +0,0 @@
|
|||||||
namespace API.DTO.Brand.Response
|
|
||||||
{
|
|
||||||
// DTO pour récupérer les informations d'une marque
|
|
||||||
public class GetBrandDto
|
|
||||||
{
|
|
||||||
// Identifiant de la marque
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Nom de la marque
|
|
||||||
public string? Name { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
// Définition de l'espace de noms pour les DTO liés à la création de classifications
|
|
||||||
namespace API.DTO.Classification.Request
|
|
||||||
{
|
|
||||||
// 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,15 +0,0 @@
|
|||||||
// Définition de l'espace de noms pour les DTO liés à la mise à jour de classifications
|
|
||||||
namespace API.DTO.Classification.Request
|
|
||||||
{
|
|
||||||
// DTO (Data Transfer Object) utilisé pour mettre à jour une classification existante
|
|
||||||
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,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO (Data Transfer Object) utilisé pour renvoyer les informations d'une classification
|
|
||||||
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,11 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// 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,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour mettre à jour une couleur existante
|
|
||||||
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,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour renvoyer les informations d'une couleur
|
|
||||||
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,11 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// 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,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour mettre à jour un effet existant
|
|
||||||
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,14 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour renvoyer les informations d'un effet
|
|
||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Login.Request;
|
|
||||||
|
|
||||||
public class ConnectLoginDto
|
|
||||||
{
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? Password { get; set; }
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Login.Request;
|
|
||||||
|
|
||||||
public class CreateLoginDto
|
|
||||||
{
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? FullName { get; set; }
|
|
||||||
public string? Password { get; set; }
|
|
||||||
}
|
|
@@ -1,9 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Login.Request;
|
|
||||||
|
|
||||||
public class UpdateLoginDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? FullName { get; set; }
|
|
||||||
public string? Password { get; set; }
|
|
||||||
}
|
|
@@ -1,6 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Login.Response;
|
|
||||||
|
|
||||||
public class GetLoginConnectDto
|
|
||||||
{
|
|
||||||
public string? Token { get; set; }
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Login.Response;
|
|
||||||
|
|
||||||
public class GetLoginDto
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string? Username { get; set; }
|
|
||||||
public string? FullName { get; set; }
|
|
||||||
public string? Password { get; set; }
|
|
||||||
public string? Salt { get; set; }
|
|
||||||
}
|
|
@@ -1,17 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour créer un nouveau matériau
|
|
||||||
public class CreateMaterialDto
|
|
||||||
{
|
|
||||||
// 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,20 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour mettre à jour un matériau existant
|
|
||||||
public class UpdateMaterialDto
|
|
||||||
{
|
|
||||||
// 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,20 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour renvoyer les informations d'un matériau
|
|
||||||
public class GetMaterialDto
|
|
||||||
{
|
|
||||||
// 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,19 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour créer un nouveau mouvement
|
|
||||||
public class CreateMovementDto
|
|
||||||
{
|
|
||||||
// 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,22 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour mettre à jour un mouvement existant
|
|
||||||
public class UpdateMovementDto
|
|
||||||
{
|
|
||||||
// ID unique du mouvement à mettre à jour
|
|
||||||
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,22 +0,0 @@
|
|||||||
// 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
|
|
||||||
{
|
|
||||||
// DTO utilisé pour renvoyer les informations d'un mouvement
|
|
||||||
public class GetMovementDto
|
|
||||||
{
|
|
||||||
// ID unique du mouvement
|
|
||||||
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,50 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Request
|
|
||||||
{
|
|
||||||
// DTO utilisé lors de la création d’un produit
|
|
||||||
public class CreateProductDto
|
|
||||||
{
|
|
||||||
// Référence interne du produit
|
|
||||||
public int References { get; set; }
|
|
||||||
|
|
||||||
// Nom du produit
|
|
||||||
public string? Name { get; set; }
|
|
||||||
|
|
||||||
// Durée de l’effet du produit
|
|
||||||
public decimal Duration { get; set; }
|
|
||||||
|
|
||||||
// Calibre du produit
|
|
||||||
public decimal Caliber { get; set; }
|
|
||||||
|
|
||||||
// Numéro d’homologation
|
|
||||||
public int 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,53 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Request
|
|
||||||
{
|
|
||||||
// DTO utilisé pour la mise à jour d’un produit existant
|
|
||||||
public class UpdateProductDto
|
|
||||||
{
|
|
||||||
// Identifiant unique du produit à modifier
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Référence interne du produit
|
|
||||||
public int References { get; set; }
|
|
||||||
|
|
||||||
// Nom du produit
|
|
||||||
public string? Name { get; set; }
|
|
||||||
|
|
||||||
// Durée de l’effet du produit
|
|
||||||
public decimal Duration { get; set; }
|
|
||||||
|
|
||||||
// Calibre du produit
|
|
||||||
public decimal Caliber { get; set; }
|
|
||||||
|
|
||||||
// Numéro d’homologation
|
|
||||||
public int 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,54 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Product.Response
|
|
||||||
{
|
|
||||||
// DTO utilisé pour renvoyer les informations complètes d’un produit
|
|
||||||
public class GetProductDto
|
|
||||||
{
|
|
||||||
// Identifiant unique du produit
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Référence interne du produit
|
|
||||||
public int Reference { get; set; }
|
|
||||||
|
|
||||||
// Nom du produit
|
|
||||||
public string? Name { get; set; }
|
|
||||||
|
|
||||||
// Durée de l’effet du produit
|
|
||||||
public decimal Duration { get; set; }
|
|
||||||
|
|
||||||
// Calibre du produit
|
|
||||||
public decimal Caliber { get; set; }
|
|
||||||
|
|
||||||
// Numéro d’homologation
|
|
||||||
public int 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,9 +0,0 @@
|
|||||||
namespace API.DTO.ProductCategory.Request
|
|
||||||
{
|
|
||||||
// DTO pour créer une catégorie de produit
|
|
||||||
public class CreateProductCategoryDto
|
|
||||||
{
|
|
||||||
// Nom de la catégorie
|
|
||||||
public string? Label { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
namespace API.DTO.ProductCategory.Request
|
|
||||||
{
|
|
||||||
// DTO pour mettre à jour une catégorie de produit
|
|
||||||
public class UpdateProductCategoryDto
|
|
||||||
{
|
|
||||||
// Identifiant de la catégorie
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Nom de la catégorie
|
|
||||||
public string? Label { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
namespace API.DTO.ProductCategory.Response
|
|
||||||
{
|
|
||||||
// DTO pour récupérer une catégorie de produit
|
|
||||||
public class GetProductCategoryDto
|
|
||||||
{
|
|
||||||
// Identifiant de la catégorie
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Nom de la catégorie
|
|
||||||
public string? Label { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,7 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
@@ -1,10 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,18 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Supplier.Request
|
|
||||||
{
|
|
||||||
// DTO pour créer un nouveau fournisseur
|
|
||||||
public class CreateSupplierDto
|
|
||||||
{
|
|
||||||
// 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 int 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,30 +0,0 @@
|
|||||||
namespace PyroFetes.DTO.Supplier.Request
|
|
||||||
{
|
|
||||||
// DTO pour mettre à jour un fournisseur existant
|
|
||||||
public class UpdateSupplierDto
|
|
||||||
{
|
|
||||||
// Identifiant du fournisseur à mettre à jour
|
|
||||||
public int Id { 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 int 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,45 +0,0 @@
|
|||||||
using PyroFetes.DTO.Supplier.Request;
|
|
||||||
|
|
||||||
namespace PyroFetes.DTO.Supplier.Response
|
|
||||||
{
|
|
||||||
// DTO pour récupérer les informations d'un fournisseur
|
|
||||||
public class GetSupplierDto
|
|
||||||
{
|
|
||||||
// Identifiant du fournisseur
|
|
||||||
public int Id { 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 int 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,40 +0,0 @@
|
|||||||
namespace API.DTO.Warehouse.Request
|
|
||||||
{
|
|
||||||
// DTO pour créer un entrepôt
|
|
||||||
public class CreateWarehouseDto
|
|
||||||
{
|
|
||||||
// Nom de l'entrepôt
|
|
||||||
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 int 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,43 +0,0 @@
|
|||||||
namespace API.DTO.Warehouse.Request
|
|
||||||
{
|
|
||||||
// DTO pour mettre à jour un entrepôt
|
|
||||||
public class UpdateWarehouseDto
|
|
||||||
{
|
|
||||||
// Identifiant de l'entrepôt à mettre à jour
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Nom de l'entrepôt
|
|
||||||
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 int 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,46 +0,0 @@
|
|||||||
namespace API.DTO.Warehouse.Response
|
|
||||||
{
|
|
||||||
// DTO pour la lecture d'un entrepôt
|
|
||||||
public class GetWarehouseDto
|
|
||||||
{
|
|
||||||
// Identifiant de l'entrepôt
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
// Nom de l'entrepôt
|
|
||||||
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 int 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,35 +0,0 @@
|
|||||||
using API.DTO.Brand.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.Brand.Request;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
|
||||||
|
|
||||||
public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateBrandDto, GetBrandDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/brands");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateBrandDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Brand brand = new ()
|
|
||||||
{
|
|
||||||
Name = req.Name
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Brands.Add(brand);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Marque créé avec succès !");
|
|
||||||
|
|
||||||
GetBrandDto responseDto = new ()
|
|
||||||
{
|
|
||||||
Name = req.Name
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
|
||||||
|
|
||||||
public class DeleteBrandRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteBrandRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/brands/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteBrandRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Brand? brandToDelete = await pyrofetesdbcontext
|
|
||||||
.Brands
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (brandToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune marque avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Brands.Remove(brandToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
using API.DTO.Brand.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
|
||||||
|
|
||||||
public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetBrandDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/brands");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
List<GetBrandDto> responseDto = await pyrofetesdbcontext.Brands
|
|
||||||
.Select(a => new GetBrandDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Name = a.Name,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Brand.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
|
||||||
|
|
||||||
public class GetBrandRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetBrandRequest, GetBrandDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/brands/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetBrandRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Brand? brand = await pyrofetesdbcontext
|
|
||||||
.Brands
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (brand == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune marque avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetBrandDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Name = brand.Name
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
using API.DTO.Brand.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.DTO.Brand.Request;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Brand;
|
|
||||||
|
|
||||||
public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateBrandDto, GetBrandDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/brands/{Id}");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateBrandDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Brand brand = new()
|
|
||||||
{
|
|
||||||
Name = req.Name
|
|
||||||
};
|
|
||||||
pyrofetesdbcontext.Add(brand);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetBrandDto response = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Name = req.Name
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
using API.DTO.Classification.Request;
|
|
||||||
using API.DTO.Classification.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Classification;
|
|
||||||
|
|
||||||
public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateClassificationDto, GetClassificationDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/classifications");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateClassificationDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Classification classification = new ()
|
|
||||||
{
|
|
||||||
Label = req.Label
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Classifications.Add(classification);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Classification créée avec succès !");
|
|
||||||
|
|
||||||
GetClassificationDto responseDto = new ()
|
|
||||||
{
|
|
||||||
Label = req.Label
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Classification;
|
|
||||||
|
|
||||||
public class DeleteClassificationRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) : Endpoint<DeleteClassificationRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/classifications/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteClassificationRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Classification? classificationToDelete = await libraryDbContext
|
|
||||||
.Classifications
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (classificationToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune classification avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
libraryDbContext.Classifications.Remove(classificationToDelete);
|
|
||||||
await libraryDbContext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
using API.DTO.Classification.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Classification;
|
|
||||||
|
|
||||||
public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetClassificationDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/classifications");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
List<GetClassificationDto> responseDto = await pyrofetesdbcontext.Classifications
|
|
||||||
.Select(a => new GetClassificationDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Label,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Classification.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Classification;
|
|
||||||
|
|
||||||
public class GetClassificationRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetClassificationRequest, GetClassificationDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/classifications/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetClassificationRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Classification? classification = await pyrofetesdbcontext
|
|
||||||
.Classifications
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (classification == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune classification avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetClassificationDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = classification.Label
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
using API.DTO.Classification.Request;
|
|
||||||
using API.DTO.Classification.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Classification;
|
|
||||||
|
|
||||||
public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateClassificationDto, GetClassificationDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/classifications");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateClassificationDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Classification classification = new()
|
|
||||||
{
|
|
||||||
Label = req.Label
|
|
||||||
};
|
|
||||||
pyrofetesdbcontext.Add(classification);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetClassificationDto response = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,36 +0,0 @@
|
|||||||
using API.DTO.Color.Request;
|
|
||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes;
|
|
||||||
|
|
||||||
namespace API.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("Api/colors"); //Création d'un endpoint pour créer une couleur avec les données de CreateColorDto
|
|
||||||
AllowAnonymous(); //Laisser passer les requêtes non authentifiées
|
|
||||||
}
|
|
||||||
|
|
||||||
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,37 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Color;
|
|
||||||
|
|
||||||
public class DeleteColorRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteColorRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("Api/colors/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteColorRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? colorToDelete = await pyrofetesdbcontext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (colorToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune couleur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Colors.Remove(colorToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Color;
|
|
||||||
|
|
||||||
public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetColorDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/colors");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetColorDto> responseDto = await pyrofetesdbcontext.Colors
|
|
||||||
.Select(a => new GetColorDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Label,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Color;
|
|
||||||
|
|
||||||
public class GetColorRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetColorRequest, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/colors/{@id}", x => new { x.Id});
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetColorRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? color = await pyrofetesdbcontext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (color == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucune couleur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = color.Id,
|
|
||||||
Label = color.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using API.DTO.Color.Request;
|
|
||||||
using API.DTO.Color.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Color;
|
|
||||||
|
|
||||||
public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateColorDto, GetColorDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("Api/colors/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateColorDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Color? colorToEdit = await pyrofetesdbcontext
|
|
||||||
.Colors
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (colorToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucune couleur avec l'id {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
colorToEdit.Label = req.Label;
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetColorDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,34 +0,0 @@
|
|||||||
using API.DTO.Effect.Request;
|
|
||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateEffectDto, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("Api/effects");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateEffectDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect effect = new()
|
|
||||||
{
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Effects.Add(effect);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine("Effect added");
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = effect.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class DeleteEffectRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteEffectRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("Api/effects/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteEffectRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effectToDelete = await pyrofetesdbcontext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effectToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun effet avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Effects.Remove(effectToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetEffectDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/effects");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetEffectDto> responseDto = await pyrofetesdbcontext.Effects
|
|
||||||
.Select(a => new GetEffectDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Label,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class GetEffectRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetEffectRequest, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/effects/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetEffectRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effect = await pyrofetesdbcontext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effect == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun effet avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = effect.Id,
|
|
||||||
Label = effect.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using API.DTO.Effect.Request;
|
|
||||||
using API.DTO.Effect.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Effect;
|
|
||||||
|
|
||||||
public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateEffectDto, GetEffectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("Api/effects/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateEffectDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Effect? effectToEdit = await pyrofetesdbcontext
|
|
||||||
.Effects
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (effectToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun effet avec l'id {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
effectToEdit.Label = req.Label;
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetEffectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Request;
|
|
||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
using PasswordGenerator;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Login;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
public class CreateLoginEndpoint(PyroFetesDbContext database) : Endpoint<CreateLoginDto, GetLoginDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/logins");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateLoginDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
string? salt = new Password().IncludeLowercase().IncludeUppercase().IncludeNumeric().LengthRequired(24).Next();
|
|
||||||
|
|
||||||
var login = new Models.Login()
|
|
||||||
{
|
|
||||||
Username = req.Username,
|
|
||||||
FullName = req.FullName,
|
|
||||||
Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt),
|
|
||||||
Salt = salt
|
|
||||||
};
|
|
||||||
|
|
||||||
database.Logins.Add(login);
|
|
||||||
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
// Pour renvoyer une erreur : Send.StringAsync("Le message d'erreur", 400);
|
|
||||||
|
|
||||||
GetLoginDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = login.Id,
|
|
||||||
Username = login.Username,
|
|
||||||
FullName = login.FullName,
|
|
||||||
Password = login.Password,
|
|
||||||
Salt = login.Salt
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Request;
|
|
||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
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("/api/logins/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteLoginRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var login = await database.Logins.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (login == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
database.Logins.Remove(login);
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,30 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Login;
|
|
||||||
|
|
||||||
public class GetAllLoginEndpoint(PyroFetesDbContext database) : EndpointWithoutRequest<List<GetLoginDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/logins");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
var logins = await database.Logins
|
|
||||||
.Select(login => new GetLoginDto()
|
|
||||||
{
|
|
||||||
Id = login.Id,
|
|
||||||
Username = login.Username,
|
|
||||||
FullName = login.FullName,
|
|
||||||
Password = login.Password,
|
|
||||||
Salt = login.Salt
|
|
||||||
})
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(logins, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
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("/api/logins/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetLoginRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var login = await database.Logins
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (login == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetLoginDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = login.Id,
|
|
||||||
Username = login.Username,
|
|
||||||
FullName = login.FullName,
|
|
||||||
Password = login.Password,
|
|
||||||
Salt = login.Salt
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,45 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Request;
|
|
||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PasswordGenerator;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Login;
|
|
||||||
|
|
||||||
public class UpdateLoginEndpoint(PyroFetesDbContext database) : Endpoint<UpdateLoginDto, GetLoginDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/logins/{@Id}", x => new {x.Id});
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateLoginDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var login = await database.Logins.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.Username = req.Username;
|
|
||||||
login.FullName = req.FullName;
|
|
||||||
login.Password = BCrypt.Net.BCrypt.HashPassword(req.Password + salt);
|
|
||||||
login.Salt = salt;
|
|
||||||
await database.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetLoginDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = login.Id,
|
|
||||||
Username = login.Username,
|
|
||||||
FullName = login.FullName,
|
|
||||||
Password = login.Password,
|
|
||||||
Salt = login.Salt
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
using PyroFetes.DTO.Login.Request;
|
|
||||||
using FastEndpoints.Security;
|
|
||||||
using PyroFetes.DTO.Login.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Login;
|
|
||||||
|
|
||||||
public class UserLoginEndpoint(PyroFetesDbContext database) : Endpoint<ConnectLoginDto, GetLoginConnectDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/login");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(ConnectLoginDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var login = await database.Logins.SingleOrDefaultAsync(x => x.Username == req.Username, ct);
|
|
||||||
|
|
||||||
if (login == null)
|
|
||||||
{
|
|
||||||
await Send.UnauthorizedAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BCrypt.Net.BCrypt.Verify(req.Password + login.Salt, login.Password))
|
|
||||||
{
|
|
||||||
var jwtToken = JwtBearer.CreateToken(
|
|
||||||
o =>
|
|
||||||
{
|
|
||||||
o.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong";
|
|
||||||
o.ExpireAt = DateTime.UtcNow.AddMinutes(15);
|
|
||||||
if (login.Role != null) o.User.Roles.Add(login.Role);
|
|
||||||
o.User.Claims.Add(("Username", login.Username)!);
|
|
||||||
o.User.Claims.Add(("FullName", login.FullName)!);
|
|
||||||
o.User["UserId"] = "001";
|
|
||||||
});
|
|
||||||
|
|
||||||
GetLoginConnectDto responseDto = new()
|
|
||||||
{
|
|
||||||
Token = jwtToken
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
else await Send.UnauthorizedAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
using API.DTO.Material.Request;
|
|
||||||
using API.DTO.Material.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Material;
|
|
||||||
|
|
||||||
public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMaterialDto, GetMaterialDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("Api/materials");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateMaterialDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Material quantity = new()
|
|
||||||
{
|
|
||||||
Name = req.Label,
|
|
||||||
Quantity = req.Quantity,
|
|
||||||
WarehouseId = req.WarehouseId,
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Materials.Add(quantity);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine("Material added");
|
|
||||||
|
|
||||||
GetMaterialDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = quantity.Id,
|
|
||||||
WarehouseId = quantity.WarehouseId,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Material;
|
|
||||||
public class DeleteMaterialRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
public class DeleteMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMaterialRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/materials/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteMaterialRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Material? materialToDelete = await pyrofetesdbcontext
|
|
||||||
.Materials
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (materialToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun matériel avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Materials.Remove(materialToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,28 +0,0 @@
|
|||||||
using API.DTO.Material.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Material;
|
|
||||||
|
|
||||||
public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMaterialDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/materials");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetMaterialDto> responseDto = await pyrofetesdbcontext.Materials
|
|
||||||
.Select(a => new GetMaterialDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Label = a.Name,
|
|
||||||
Quantity = a.Quantity,
|
|
||||||
WarehouseId = a.WarehouseId,
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Material.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Material;
|
|
||||||
|
|
||||||
public class GetMaterialRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<GetMaterialRequest, GetMaterialDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("Api/materials/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetMaterialRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Material? material = await pyrofetesdbcontext
|
|
||||||
.Materials
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (material == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun matériel avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetMaterialDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = material.Id,
|
|
||||||
Label = material.Name,
|
|
||||||
WarehouseId = material.WarehouseId,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.Material.Request;
|
|
||||||
using API.DTO.Material.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Material;
|
|
||||||
|
|
||||||
public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMaterialDto, GetMaterialDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("Api/materials/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateMaterialDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.Material? materialToEdit = await pyrofetesdbcontext
|
|
||||||
.Materials
|
|
||||||
.SingleOrDefaultAsync(x => x.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (materialToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Aucun matériel avec l'id {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
|
|
||||||
}
|
|
||||||
materialToEdit.Name = req.Label;
|
|
||||||
materialToEdit.WarehouseId = req.WarehouseId;
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetMaterialDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
WarehouseId = req.WarehouseId,
|
|
||||||
};
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,41 +0,0 @@
|
|||||||
using API.DTO.Movement.Request;
|
|
||||||
using API.DTO.Movement.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Movement;
|
|
||||||
|
|
||||||
public class CreateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateMovementDto, GetMovementDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/movements");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateMovementDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Movement movement = new ()
|
|
||||||
{
|
|
||||||
Date = req.Date,
|
|
||||||
Start = req.Start,
|
|
||||||
Arrival = req.Arrival,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Movements.Add(movement);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Movement créée avec succès !");
|
|
||||||
|
|
||||||
GetMovementDto responseDto = new ()
|
|
||||||
{
|
|
||||||
Date = req.Date,
|
|
||||||
Start = req.Start,
|
|
||||||
Arrival = req.Arrival,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,38 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Movement;
|
|
||||||
|
|
||||||
public class DeleteMovementRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteMovementRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/Movements/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteMovementRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Movement? movementToDelete = await pyrofetesdbcontext
|
|
||||||
.Movements
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (movementToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucune mouvement avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Movements.Remove(movementToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,31 +0,0 @@
|
|||||||
using API.DTO.Movement.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Movement;
|
|
||||||
|
|
||||||
public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetMovementDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/movements");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
List<GetMovementDto> responseDto = await pyrofetesdbcontext.Movements
|
|
||||||
.Select(a => new GetMovementDto
|
|
||||||
{
|
|
||||||
Id = a.Id,
|
|
||||||
Date = a.Date,
|
|
||||||
Start = a.Start,
|
|
||||||
Arrival = a.Arrival,
|
|
||||||
Quantity = a.Quantity
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,45 +0,0 @@
|
|||||||
using API.DTO.Movement.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Movement;
|
|
||||||
|
|
||||||
public class GetMovementRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetMovementRequest, GetMovementDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/movements/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetMovementRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Movement? movement = await pyrofetesdbcontext
|
|
||||||
.Movements
|
|
||||||
.SingleOrDefaultAsync(a => a.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (movement == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun mouvement avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetMovementDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Date = movement.Date,
|
|
||||||
Start = movement.Start,
|
|
||||||
Arrival = movement.Arrival,
|
|
||||||
Quantity = movement.Quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
using API.DTO.Movement.Request;
|
|
||||||
using API.DTO.Movement.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Movement;
|
|
||||||
|
|
||||||
public class UpdateMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateMovementDto, GetMovementDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/movements");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateMovementDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
|
|
||||||
Models.Movement movement = new()
|
|
||||||
{
|
|
||||||
Date = req.Date,
|
|
||||||
Start = req.Start,
|
|
||||||
Arrival = req.Arrival,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
pyrofetesdbcontext.Add(movement);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetMovementDto response = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Date = req.Date,
|
|
||||||
Start = req.Start,
|
|
||||||
Arrival = req.Arrival,
|
|
||||||
Quantity = req.Quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,105 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
|
||||||
|
|
||||||
public class CreateProductEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<CreateProductDto, GetProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/products");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateProductDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var product = new Models.Product
|
|
||||||
{
|
|
||||||
Reference = req.References.ToString(),
|
|
||||||
Name = req.Name!,
|
|
||||||
Duration = req.Duration,
|
|
||||||
Caliber = req.Caliber,
|
|
||||||
ApprovalNumber = req.ApprovalNumber,
|
|
||||||
Weight = req.Weight,
|
|
||||||
Nec = req.Nec,
|
|
||||||
Image = req.Image!,
|
|
||||||
Link = req.Link!,
|
|
||||||
ProductCategoryId = req.ProductCategoryId,
|
|
||||||
ClassificationId = req.ClassificationId
|
|
||||||
};
|
|
||||||
|
|
||||||
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,
|
|
||||||
Reference = req.References,
|
|
||||||
Name = req.Name,
|
|
||||||
Duration = req.Duration,
|
|
||||||
Caliber = req.Caliber,
|
|
||||||
ApprovalNumber = req.ApprovalNumber,
|
|
||||||
Weight = req.Weight,
|
|
||||||
Nec = req.Nec,
|
|
||||||
SellingPrice = req.SellingPrice,
|
|
||||||
Image = req.Image,
|
|
||||||
Link = req.Link,
|
|
||||||
ProductCategoryId = req.ProductCategoryId,
|
|
||||||
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(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,59 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
|
||||||
|
|
||||||
public class DeleteProductRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint<DeleteProductRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/products/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteProductRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// Récupérer le produit
|
|
||||||
var productToDelete = await db.Products
|
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (productToDelete is null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer les liaisons Price
|
|
||||||
var relatedPrices = await db.Prices
|
|
||||||
.Where(p => p.ProductId == req.Id)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
if (relatedPrices.Any())
|
|
||||||
{
|
|
||||||
db.Prices.RemoveRange(relatedPrices);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer les liaisons WarehouseProduct
|
|
||||||
var relatedWarehouseProducts = await db.WarehouseProducts
|
|
||||||
.Where(wp => wp.ProductId == req.Id)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
if (relatedWarehouseProducts.Any())
|
|
||||||
{
|
|
||||||
db.WarehouseProducts.RemoveRange(relatedWarehouseProducts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer le produit
|
|
||||||
db.Products.Remove(productToDelete);
|
|
||||||
|
|
||||||
await db.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine($"Produit {req.Id}, ses prix et ses entrepôts liés ont été supprimés avec succès.");
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,63 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
|
||||||
|
|
||||||
public class GetAllProductsEndpoint(PyroFetesDbContext db)
|
|
||||||
: EndpointWithoutRequest<List<GetProductDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/products");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
// Inclure toutes les relations nécessaires : Prices + WarehouseProducts + Warehouse
|
|
||||||
var products = await db.Products
|
|
||||||
.Include(p => p.Prices)
|
|
||||||
.Include(p => p.WarehouseProducts)
|
|
||||||
.ThenInclude(wp => wp.Warehouse)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
var responseDto = products.Select(p => new GetProductDto
|
|
||||||
{
|
|
||||||
Id = p.Id,
|
|
||||||
// Le modèle Product contient "Reference" (string) — pas "References" (int)
|
|
||||||
Reference = int.TryParse(p.Reference, out var refInt) ? refInt : 0,
|
|
||||||
Name = p.Name,
|
|
||||||
Duration = p.Duration,
|
|
||||||
Caliber = p.Caliber,
|
|
||||||
ApprovalNumber = p.ApprovalNumber,
|
|
||||||
Weight = p.Weight,
|
|
||||||
Nec = p.Nec,
|
|
||||||
// Le prix de vente n’est pas dans Product, on le récupère via Prices
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
|
||||||
|
|
||||||
public class GetProductRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetProductEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<GetProductRequest, GetProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/products/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetProductRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// Inclure toutes les relations : Prices + WarehouseProducts + Warehouse
|
|
||||||
var product = await db.Products
|
|
||||||
.Include(p => p.Prices)
|
|
||||||
.Include(p => p.WarehouseProducts)
|
|
||||||
.ThenInclude(wp => wp.Warehouse)
|
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (product == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun produit avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseDto = new GetProductDto
|
|
||||||
{
|
|
||||||
Id = product.Id,
|
|
||||||
|
|
||||||
// Le modèle Product contient "Reference" (string), pas "References" (int)
|
|
||||||
Reference = int.TryParse(product.Reference, out var refInt) ? refInt : 0,
|
|
||||||
|
|
||||||
Name = product.Name,
|
|
||||||
Duration = product.Duration,
|
|
||||||
Caliber = product.Caliber,
|
|
||||||
ApprovalNumber = product.ApprovalNumber,
|
|
||||||
Weight = product.Weight,
|
|
||||||
Nec = product.Nec,
|
|
||||||
|
|
||||||
// Le prix de vente n’est pas dans Product → récupéré via Price
|
|
||||||
SellingPrice = product.Prices.FirstOrDefault()?.SellingPrice ?? 0,
|
|
||||||
|
|
||||||
Image = product.Image,
|
|
||||||
Link = product.Link,
|
|
||||||
ClassificationId = product.ClassificationId,
|
|
||||||
ProductCategoryId = product.ProductCategoryId,
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,111 +0,0 @@
|
|||||||
using PyroFetes.DTO.Product.Request;
|
|
||||||
using PyroFetes.DTO.Product.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Product;
|
|
||||||
|
|
||||||
// Endpoint permettant de mettre à jour un produit existant
|
|
||||||
public class UpdateProductEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<UpdateProductDto, GetProductDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
// Route HTTP PUT avec un paramètre d'identifiant dans l'URL
|
|
||||||
Put("/api/products/{@id}", x => new { x.Id });
|
|
||||||
|
|
||||||
// Autorise les requêtes anonymes (sans authentification)
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateProductDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// Recherche du produit à mettre à jour, en incluant les relations Prices et WarehouseProducts
|
|
||||||
var product = await db.Products
|
|
||||||
.Include(p => p.Prices)
|
|
||||||
.Include(p => p.WarehouseProducts)
|
|
||||||
.SingleOrDefaultAsync(p => p.Id == req.Id, ct);
|
|
||||||
|
|
||||||
// Si le produit n'existe pas, on retourne une réponse 404
|
|
||||||
if (product is null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour des propriétés principales du produit
|
|
||||||
product.Reference = req.References.ToString(); // Converti int → string
|
|
||||||
product.Name = req.Name;
|
|
||||||
product.Duration = req.Duration;
|
|
||||||
product.Caliber = req.Caliber;
|
|
||||||
product.ApprovalNumber = req.ApprovalNumber;
|
|
||||||
product.Weight = req.Weight;
|
|
||||||
product.Nec = req.Nec;
|
|
||||||
product.Image = req.Image;
|
|
||||||
product.Link = req.Link;
|
|
||||||
product.ClassificationId = req.ClassificationId;
|
|
||||||
product.ProductCategoryId = req.ProductCategoryId;
|
|
||||||
|
|
||||||
// Mise à jour des prix fournisseurs associés
|
|
||||||
db.Prices.RemoveRange(product.Prices);
|
|
||||||
foreach (var s in req.Suppliers)
|
|
||||||
{
|
|
||||||
db.Prices.Add(new Price
|
|
||||||
{
|
|
||||||
ProductId = product.Id,
|
|
||||||
SupplierId = s.SupplierId,
|
|
||||||
SellingPrice = s.SellingPrice
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mise à jour des entrepôts associés
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Construction de la réponse renvoyée au client
|
|
||||||
var response = new GetProductDto
|
|
||||||
{
|
|
||||||
Id = product.Id,
|
|
||||||
Reference = req.References, // DTO garde int pour cohérence
|
|
||||||
Name = req.Name,
|
|
||||||
Duration = req.Duration,
|
|
||||||
Caliber = req.Caliber,
|
|
||||||
ApprovalNumber = req.ApprovalNumber,
|
|
||||||
Weight = req.Weight,
|
|
||||||
Nec = req.Nec,
|
|
||||||
// Le prix de vente est pris depuis Prices
|
|
||||||
SellingPrice = req.Suppliers.FirstOrDefault()?.SellingPrice ?? 0,
|
|
||||||
Image = req.Image,
|
|
||||||
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(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,37 +0,0 @@
|
|||||||
using API.DTO.ProductCategory.Request;
|
|
||||||
using API.DTO.ProductCategory.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
|
||||||
|
|
||||||
public class CreateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<CreateProductCategoryDto, GetProductCategoryDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/productcategories");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateProductCategoryDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.ProductCategory productCategory = new ()
|
|
||||||
{
|
|
||||||
Label = req.Label,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.ProductCategories.Add(productCategory);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
Console.WriteLine("Category créé avec succès !");
|
|
||||||
|
|
||||||
GetProductCategoryDto responseDto = new ()
|
|
||||||
{
|
|
||||||
Id = productCategory.Id,
|
|
||||||
Label = productCategory.Label
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,36 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
|
||||||
|
|
||||||
public class DeleteProductCategoryRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteProductCategoryRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/productcategories/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteProductCategoryRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.ProductCategory? productCategoryToDelete = await pyrofetesdbcontext
|
|
||||||
.ProductCategories
|
|
||||||
.SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (productCategoryToDelete == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pyrofetesdbcontext.ProductCategories.Remove(productCategoryToDelete);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,27 +0,0 @@
|
|||||||
using API.DTO.ProductCategory.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
|
||||||
|
|
||||||
public class GetAllProductCategoriesEndpoint(PyroFetesDbContext pyrofetesdbcontext) : EndpointWithoutRequest<List<GetProductCategoryDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/productcategories");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
List<GetProductCategoryDto> responseDto = await pyrofetesdbcontext.ProductCategories
|
|
||||||
.Select(pc => new GetProductCategoryDto()
|
|
||||||
{
|
|
||||||
Id = pc.Id,
|
|
||||||
Label = pc.Label
|
|
||||||
}
|
|
||||||
).ToListAsync(ct);
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,42 +0,0 @@
|
|||||||
using API.DTO.ProductCategory.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
|
||||||
|
|
||||||
public class GetProductCategoryRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class GetProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<GetProductCategoryRequest, GetProductCategoryDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/productcategory/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetProductCategoryRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.ProductCategory? productCategory = await pyrofetesdbcontext
|
|
||||||
.ProductCategories
|
|
||||||
.SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (productCategory == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
GetProductCategoryDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = productCategory.Id,
|
|
||||||
Label = productCategory.Label
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,39 +0,0 @@
|
|||||||
using API.DTO.ProductCategory.Request;
|
|
||||||
using API.DTO.ProductCategory.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.ProductCategory;
|
|
||||||
|
|
||||||
public class UpdateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<UpdateProductCategoryDto, GetProductCategoryDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/productcategory/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateProductCategoryDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
Models.ProductCategory? productCategoryToEdit = await pyrofetesdbcontext
|
|
||||||
.ProductCategories
|
|
||||||
.SingleOrDefaultAsync(pc => pc.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (productCategoryToEdit == null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
productCategoryToEdit.Label = req.Label;
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
GetProductCategoryDto responseDto = new()
|
|
||||||
{
|
|
||||||
Id = req.Id,
|
|
||||||
Label = req.Label,
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(responseDto, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,62 +0,0 @@
|
|||||||
using PyroFetes.DTO.Supplier.Request;
|
|
||||||
using PyroFetes.DTO.Supplier.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
|
||||||
|
|
||||||
public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
|
||||||
: Endpoint<CreateSupplierDto, GetSupplierDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/suppliers");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateSupplierDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var supplier = new Models.Supplier
|
|
||||||
{
|
|
||||||
Name = req.Name,
|
|
||||||
Email = req.Email,
|
|
||||||
Phone = req.PhoneNumber,
|
|
||||||
Address = req.Adress,
|
|
||||||
ZipCode = req.ZipCode,
|
|
||||||
City = req.City
|
|
||||||
};
|
|
||||||
|
|
||||||
pyrofetesdbcontext.Suppliers.Add(supplier);
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
// Ajout des liaisons Price si produits renseignés
|
|
||||||
if (req.Products is not null && req.Products.Any())
|
|
||||||
{
|
|
||||||
foreach (var p in req.Products)
|
|
||||||
{
|
|
||||||
var price = new Price
|
|
||||||
{
|
|
||||||
SupplierId = supplier.Id,
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
SellingPrice = p.SellingPrice
|
|
||||||
};
|
|
||||||
pyrofetesdbcontext.Prices.Add(price);
|
|
||||||
}
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = new GetSupplierDto
|
|
||||||
{
|
|
||||||
Id = supplier.Id,
|
|
||||||
Name = supplier.Name,
|
|
||||||
Email = supplier.Email,
|
|
||||||
PhoneNumber = supplier.Phone,
|
|
||||||
Adress = supplier.Address,
|
|
||||||
ZipCode = supplier.ZipCode,
|
|
||||||
City = supplier.City
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,51 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
|
||||||
|
|
||||||
public class DeleteSupplierRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<DeleteSupplierRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/suppliers/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(DeleteSupplierRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var supplierToDelete = await pyrofetesdbcontext
|
|
||||||
.Suppliers
|
|
||||||
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (supplierToDelete is null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer les liaisons Price avant le fournisseur
|
|
||||||
var relatedPrices = await pyrofetesdbcontext.Prices
|
|
||||||
.Where(p => p.SupplierId == req.Id)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
if (relatedPrices.Any())
|
|
||||||
{
|
|
||||||
pyrofetesdbcontext.Prices.RemoveRange(relatedPrices);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Supprimer le fournisseur
|
|
||||||
pyrofetesdbcontext.Suppliers.Remove(supplierToDelete);
|
|
||||||
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
Console.WriteLine($"Fournisseur {req.Id} et ses prix liés supprimés avec succès.");
|
|
||||||
|
|
||||||
await Send.NoContentAsync(ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
using PyroFetes.DTO.Supplier.Response;
|
|
||||||
using PyroFetes.DTO.Supplier.Request;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
|
||||||
|
|
||||||
public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
|
||||||
: EndpointWithoutRequest<List<GetSupplierDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/suppliers");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
var suppliers = await pyrofetesdbcontext.Suppliers
|
|
||||||
.Include(s => s.Prices)
|
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,55 +0,0 @@
|
|||||||
using PyroFetes.DTO.Supplier.Request;
|
|
||||||
using PyroFetes.DTO.Supplier.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
|
||||||
|
|
||||||
public class GetSupplierRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
|
|
||||||
: Endpoint<GetSupplierRequest, GetSupplierDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/suppliers/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetSupplierRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var supplier = await pyrofetesdbcontext.Suppliers
|
|
||||||
.Include(s => s.Prices)
|
|
||||||
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (supplier == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun fournisseur avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseDto = new GetSupplierDto
|
|
||||||
{
|
|
||||||
Id = supplier.Id,
|
|
||||||
Name = supplier.Name!,
|
|
||||||
Email = supplier.Email!,
|
|
||||||
PhoneNumber = supplier.Phone!,
|
|
||||||
Adress = supplier.Address!,
|
|
||||||
ZipCode = supplier.ZipCode,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,70 +0,0 @@
|
|||||||
using PyroFetes.DTO.Supplier.Request;
|
|
||||||
using PyroFetes.DTO.Supplier.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Supplier;
|
|
||||||
|
|
||||||
public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<UpdateSupplierDto, GetSupplierDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Put("/api/suppliers/{@id}", x => new { x.Id });
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateSupplierDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var supplierToEdit = await pyrofetesdbcontext
|
|
||||||
.Suppliers
|
|
||||||
.Include(s => s.Prices)
|
|
||||||
.SingleOrDefaultAsync(s => s.Id == req.Id, ct);
|
|
||||||
|
|
||||||
if (supplierToEdit is null)
|
|
||||||
{
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
supplierToEdit.Name = req.Name;
|
|
||||||
supplierToEdit.Email = req.Email;
|
|
||||||
supplierToEdit.Phone = req.PhoneNumber;
|
|
||||||
supplierToEdit.Address = req.Adress;
|
|
||||||
supplierToEdit.ZipCode = req.ZipCode;
|
|
||||||
supplierToEdit.City = req.City;
|
|
||||||
|
|
||||||
if (req.Products is not null)
|
|
||||||
{
|
|
||||||
// Supprimer les anciennes liaisons
|
|
||||||
var existingPrices = pyrofetesdbcontext.Prices
|
|
||||||
.Where(p => p.SupplierId == supplierToEdit.Id);
|
|
||||||
pyrofetesdbcontext.Prices.RemoveRange(existingPrices);
|
|
||||||
|
|
||||||
// Ajouter les nouvelles liaisons
|
|
||||||
foreach (var p in req.Products)
|
|
||||||
{
|
|
||||||
pyrofetesdbcontext.Prices.Add(new Price
|
|
||||||
{
|
|
||||||
SupplierId = supplierToEdit.Id,
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
SellingPrice = p.SellingPrice
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await pyrofetesdbcontext.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
var response = new GetSupplierDto
|
|
||||||
{
|
|
||||||
Id = supplierToEdit.Id,
|
|
||||||
Name = supplierToEdit.Name,
|
|
||||||
Email = supplierToEdit.Email,
|
|
||||||
PhoneNumber = supplierToEdit.Phone,
|
|
||||||
Adress = supplierToEdit.Address,
|
|
||||||
ZipCode = supplierToEdit.ZipCode,
|
|
||||||
City = supplierToEdit.City
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,63 +0,0 @@
|
|||||||
using API.DTO.Warehouse.Request;
|
|
||||||
using API.DTO.Warehouse.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
|
||||||
|
|
||||||
public class CreateWarehouseEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<CreateWarehouseDto, GetWarehouseDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Post("/api/warehouse");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CreateWarehouseDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
var warehouse = new Models.Warehouse
|
|
||||||
{
|
|
||||||
Name = req.Name,
|
|
||||||
MaxWeight = req.MaxWeight,
|
|
||||||
Current = req.Current,
|
|
||||||
MinWeight = req.MinWeight,
|
|
||||||
Address = req.Adress,
|
|
||||||
ZipCode = req.ZipCode,
|
|
||||||
City = req.City
|
|
||||||
};
|
|
||||||
|
|
||||||
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,
|
|
||||||
Name = warehouse.Name,
|
|
||||||
MaxWeight = warehouse.MaxWeight,
|
|
||||||
Current = warehouse.Current,
|
|
||||||
MinWeight = warehouse.MinWeight,
|
|
||||||
Adress = warehouse.Address,
|
|
||||||
ZipCode = warehouse.ZipCode,
|
|
||||||
City = warehouse.City
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,50 +0,0 @@
|
|||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
|
||||||
|
|
||||||
public class DeleteWarehouseRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint<DeleteWarehouseRequest>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Delete("/api/warehouse/{id}");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// On charge aussi les WarehouseProducts liés pour les supprimer proprement
|
|
||||||
var warehouseToDelete = await db.Warehouses
|
|
||||||
.Include(w => w.WarehouseProducts)
|
|
||||||
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (warehouseToDelete == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun entrepôt avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🔹 Suppression des relations WarehouseProduct avant l'entrepôt
|
|
||||||
var relatedWarehouseProducts = await db.WarehouseProducts
|
|
||||||
.Where(wp => wp.WarehouseId == req.Id)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
if (relatedWarehouseProducts.Any())
|
|
||||||
{
|
|
||||||
db.WarehouseProducts.RemoveRange(relatedWarehouseProducts);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🔹 Suppression de 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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,46 +0,0 @@
|
|||||||
using API.DTO.Warehouse.Response;
|
|
||||||
using API.DTO.Warehouse.Request;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
|
||||||
|
|
||||||
public class GetAllWarehouseEndpoint(PyroFetesDbContext db)
|
|
||||||
: EndpointWithoutRequest<List<GetWarehouseDto>>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
Get("/api/warehouses");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
// 🔹 On inclut les relations avec WarehouseProducts et Product
|
|
||||||
var warehouses = await db.Warehouses
|
|
||||||
.Include(w => w.WarehouseProducts)
|
|
||||||
.ThenInclude(wp => wp.Product)
|
|
||||||
.ToListAsync(ct);
|
|
||||||
|
|
||||||
var response = warehouses.Select(w => new GetWarehouseDto
|
|
||||||
{
|
|
||||||
Id = w.Id,
|
|
||||||
Name = w.Name,
|
|
||||||
MaxWeight = w.MaxWeight,
|
|
||||||
Current = w.Current,
|
|
||||||
MinWeight = w.MinWeight,
|
|
||||||
Adress = w.Address,
|
|
||||||
ZipCode = w.ZipCode,
|
|
||||||
City = w.City,
|
|
||||||
Products = w.WarehouseProducts.Select(wp => new WarehouseProductDto
|
|
||||||
{
|
|
||||||
ProductId = wp.ProductId,
|
|
||||||
ProductName = wp.Product?.Name,
|
|
||||||
Quantity = wp.Quantity
|
|
||||||
}).ToList()
|
|
||||||
}).ToList();
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,58 +0,0 @@
|
|||||||
using API.DTO.Warehouse.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
|
||||||
|
|
||||||
public class GetWarehouseRequest
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GetWarehouseEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<GetWarehouseRequest, GetWarehouseDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
// Pas de "@id" ici, juste {id}
|
|
||||||
Get("/api/warehouses/{Id}");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(GetWarehouseRequest req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// 🔹 Inclut les produits associés à cet entrepôt
|
|
||||||
var warehouse = await db.Warehouses
|
|
||||||
.Include(w => w.WarehouseProducts)
|
|
||||||
.ThenInclude(wp => wp.Product)
|
|
||||||
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (warehouse == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($" Aucun entrepôt avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var response = new GetWarehouseDto
|
|
||||||
{
|
|
||||||
Id = warehouse.Id,
|
|
||||||
Name = warehouse.Name!,
|
|
||||||
MaxWeight = warehouse.MaxWeight,
|
|
||||||
Current = warehouse.Current,
|
|
||||||
MinWeight = warehouse.MinWeight,
|
|
||||||
Adress = warehouse.Address!,
|
|
||||||
ZipCode = warehouse.ZipCode,
|
|
||||||
City = warehouse.City!,
|
|
||||||
Products = warehouse.WarehouseProducts.Select(wp => new WarehouseProductDto
|
|
||||||
{
|
|
||||||
ProductId = wp.ProductId,
|
|
||||||
ProductName = wp.Product?.Name,
|
|
||||||
Quantity = wp.Quantity
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,86 +0,0 @@
|
|||||||
using API.DTO.Warehouse.Request;
|
|
||||||
using API.DTO.Warehouse.Response;
|
|
||||||
using FastEndpoints;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PyroFetes.Models;
|
|
||||||
|
|
||||||
namespace PyroFetes.Endpoints.Warehouse;
|
|
||||||
|
|
||||||
public class UpdateWarehouseEndpoint(PyroFetesDbContext db)
|
|
||||||
: Endpoint<UpdateWarehouseDto, GetWarehouseDto>
|
|
||||||
{
|
|
||||||
public override void Configure()
|
|
||||||
{
|
|
||||||
// Utilise {id} plutôt que {@id}
|
|
||||||
Put("/api/warehouses/{Id}");
|
|
||||||
AllowAnonymous();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task HandleAsync(UpdateWarehouseDto req, CancellationToken ct)
|
|
||||||
{
|
|
||||||
// 🔹 On inclut les produits existants pour pouvoir les modifier
|
|
||||||
var warehouseToEdit = await db.Warehouses
|
|
||||||
.Include(w => w.WarehouseProducts)
|
|
||||||
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);
|
|
||||||
|
|
||||||
if (warehouseToEdit == null)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Aucun entrepôt avec l'ID {req.Id} trouvé.");
|
|
||||||
await Send.NotFoundAsync(ct);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 🔹 Mise à jour des champs de base
|
|
||||||
warehouseToEdit.Name = req.Name;
|
|
||||||
warehouseToEdit.MaxWeight = req.MaxWeight;
|
|
||||||
warehouseToEdit.Current = req.Current;
|
|
||||||
warehouseToEdit.MinWeight = req.MinWeight;
|
|
||||||
warehouseToEdit.Address = req.Adress;
|
|
||||||
warehouseToEdit.ZipCode = req.ZipCode;
|
|
||||||
warehouseToEdit.City = req.City;
|
|
||||||
|
|
||||||
// 🔹 Gestion des produits associés
|
|
||||||
if (req.Products is not null)
|
|
||||||
{
|
|
||||||
// On supprime les anciens liens pour recréer proprement
|
|
||||||
var existingLinks = warehouseToEdit.WarehouseProducts.ToList();
|
|
||||||
if (existingLinks.Any())
|
|
||||||
db.WarehouseProducts.RemoveRange(existingLinks);
|
|
||||||
|
|
||||||
foreach (var p in req.Products)
|
|
||||||
{
|
|
||||||
var newLink = new WarehouseProduct
|
|
||||||
{
|
|
||||||
WarehouseId = warehouseToEdit.Id,
|
|
||||||
ProductId = p.ProductId,
|
|
||||||
Quantity = p.Quantity
|
|
||||||
};
|
|
||||||
db.WarehouseProducts.Add(newLink);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.SaveChangesAsync(ct);
|
|
||||||
|
|
||||||
// 🔹 On renvoie la version mise à jour
|
|
||||||
var response = new GetWarehouseDto
|
|
||||||
{
|
|
||||||
Id = warehouseToEdit.Id,
|
|
||||||
Name = warehouseToEdit.Name,
|
|
||||||
MaxWeight = warehouseToEdit.MaxWeight,
|
|
||||||
Current = warehouseToEdit.Current,
|
|
||||||
MinWeight = warehouseToEdit.MinWeight,
|
|
||||||
Adress = warehouseToEdit.Address,
|
|
||||||
ZipCode = warehouseToEdit.ZipCode,
|
|
||||||
City = warehouseToEdit.City,
|
|
||||||
Products = warehouseToEdit.WarehouseProducts.Select(wp => new WarehouseProductDto
|
|
||||||
{
|
|
||||||
ProductId = wp.ProductId,
|
|
||||||
ProductName = wp.Product?.Name,
|
|
||||||
Quantity = wp.Quantity
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
|
|
||||||
Console.WriteLine($"Entrepôt {warehouseToEdit.Name} mis à jour avec succès.");
|
|
||||||
await Send.OkAsync(response, ct);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,13 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace PyroFetes.Models;
|
|
||||||
|
|
||||||
public class Login
|
|
||||||
{
|
|
||||||
[Key] public int Id { get; set; }
|
|
||||||
[Required, MaxLength(100)] public string? Username { get; set; }
|
|
||||||
[Required, MaxLength(200)] public string? FullName { get; set; }
|
|
||||||
[Required, Length(60, 60)] public string? Password { get; set; }
|
|
||||||
[Required, Length(24, 24)] public string? Salt { get; set; }
|
|
||||||
[Required, MaxLength(100)] public string? Role { get; set; }
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user