7 Commits

84 changed files with 187 additions and 5756 deletions

View File

@@ -1,7 +0,0 @@
namespace PyroFetes.DTO.Login.Request;
public class ConnectLoginDto
{
public string? Username { get; set; }
public string? Password { get; set; }
}

View File

@@ -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; }
}

View File

@@ -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; }
}

View File

@@ -1,6 +0,0 @@
namespace PyroFetes.DTO.Login.Response;
public class GetLoginConnectDto
{
public string? Token { get; set; }
}

View File

@@ -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; }
}

View File

@@ -6,7 +6,7 @@ namespace PyroFetes.DTO.Product.Request
public class CreateProductDto
{
// Référence interne du produit
public int References { get; set; }
public string? Reference { get; set; }
// Nom du produit
public string? Name { get; set; }
@@ -15,10 +15,10 @@ namespace PyroFetes.DTO.Product.Request
public decimal Duration { get; set; }
// Calibre du produit
public decimal Caliber { get; set; }
public int Caliber { get; set; }
// Numéro dhomologation
public int ApprovalNumber { get; set; }
public string? ApprovalNumber { get; set; }
// Poids du produit
public decimal Weight { get; set; }

View File

@@ -9,7 +9,7 @@ namespace PyroFetes.DTO.Product.Request
public int Id { get; set; }
// Référence interne du produit
public int References { get; set; }
public string? Reference { get; set; }
// Nom du produit
public string? Name { get; set; }
@@ -18,10 +18,10 @@ namespace PyroFetes.DTO.Product.Request
public decimal Duration { get; set; }
// Calibre du produit
public decimal Caliber { get; set; }
public int Caliber { get; set; }
// Numéro dhomologation
public int ApprovalNumber { get; set; }
public string? ApprovalNumber { get; set; }
// Poids du produit
public decimal Weight { get; set; }

View File

@@ -10,7 +10,7 @@ namespace PyroFetes.DTO.Product.Response
public int Id { get; set; }
// Référence interne du produit
public int Reference { get; set; }
public string? Reference { get; set; }
// Nom du produit
public string? Name { get; set; }
@@ -19,10 +19,10 @@ namespace PyroFetes.DTO.Product.Response
public decimal Duration { get; set; }
// Calibre du produit
public decimal Caliber { get; set; }
public int Caliber { get; set; }
// Numéro dhomologation
public int ApprovalNumber { get; set; }
public string? ApprovalNumber { get; set; }
// Poids du produit
public decimal Weight { get; set; }

View File

@@ -4,22 +4,22 @@
public class CreateSupplierDto
{
// Nom du fournisseur
public string Name { get; set; }
public string? Name { get; set; }
// Email du fournisseur
public string Email { get; set; }
public string? Email { get; set; }
// Numéro de téléphone du fournisseur
public string PhoneNumber { get; set; }
public string? PhoneNumber { get; set; }
// Adresse du fournisseur
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal de l'adresse
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville de l'adresse
public string City { get; set; }
public string? City { get; set; }
// Liste des produits fournis par ce fournisseur dans la classe SupplierProductPriceDto
public List<SupplierProductPriceDto>? Products { get; set; }

View File

@@ -7,22 +7,22 @@
public int Id { get; set; }
// Nom du fournisseur
public string Name { get; set; }
public string? Name { get; set; }
// Email du fournisseur
public string Email { get; set; }
public string? Email { get; set; }
// Numéro de téléphone du fournisseur
public string PhoneNumber { get; set; }
public string? PhoneNumber { get; set; }
// Adresse du fournisseur
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal de l'adresse
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville de l'adresse
public string City { get; set; }
public string? City { get; set; }
// Liste des produits fournis par ce fournisseur relié à la classe SupplierProductPriceDto
public List<SupplierProductPriceDto>? Products { get; set; }

View File

@@ -9,22 +9,22 @@ namespace PyroFetes.DTO.Supplier.Response
public int Id { get; set; }
// Nom du fournisseur
public string Name { get; set; }
public string? Name { get; set; }
// Email du fournisseur
public string Email { get; set; }
public string? Email { get; set; }
// Numéro de téléphone
public string PhoneNumber { get; set; }
public string? PhoneNumber { get; set; }
// Adresse du fournisseur
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville
public string City { get; set; }
public string? City { get; set; }
// Liste des produits fournis par la classe SupplierProductPriceDto
public List<SupplierProductPriceDto> Products { get; set; } = new();

View File

@@ -4,7 +4,7 @@
public class CreateWarehouseDto
{
// Nom de l'entrepôt
public string Name { get; set; }
public string? Name { get; set; }
// Poids maximal que l'entrepôt peut contenir
public int MaxWeight { get; set; }
@@ -16,13 +16,13 @@
public int MinWeight { get; set; }
// Adresse de l'entrepôt
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville
public string City { get; set; }
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; }

View File

@@ -7,7 +7,7 @@
public int Id { get; set; }
// Nom de l'entrepôt
public string Name { get; set; }
public string? Name { get; set; }
// Poids maximal que l'entrepôt peut contenir
public int MaxWeight { get; set; }
@@ -19,13 +19,13 @@
public int MinWeight { get; set; }
// Adresse de l'entrepôt
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville
public string City { get; set; }
public string? City { get; set; }
// Liste des produits à mettre à jour dans cet entrepôt
public List<UpdateWarehouseProductDto>? Products { get; set; }

View File

@@ -7,7 +7,7 @@
public int Id { get; set; }
// Nom de l'entrepôt
public string Name { get; set; }
public string? Name { get; set; }
// Poids maximal que l'entrepôt peut contenir
public int MaxWeight { get; set; }
@@ -19,13 +19,13 @@
public int MinWeight { get; set; }
// Adresse de l'entrepôt
public string Adress { get; set; }
public string? Adress { get; set; }
// Code postal
public int ZipCode { get; set; }
public string? ZipCode { get; set; }
// Ville
public string City { get; set; }
public string? City { get; set; }
// Liste des produits stockés dans l'entrepôt
public List<WarehouseProductDto>? Products { get; set; }

View File

@@ -8,7 +8,7 @@ public class CreateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Post("/api/brands");
Post("/brands");
AllowAnonymous();
}

View File

@@ -12,7 +12,7 @@ public class DeleteBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Delete("/api/brands/{@id}", x => new { x.Id });
Delete("/brands/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllBrandsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
{
public override void Configure()
{
Get("/api/brands");
Get("/brands");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoint<G
{
public override void Configure()
{
Get("/api/brands/{@id}", x => new { x.Id });
Get("/brands/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class UpdateBrandEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Put("/api/brands/{Id}");
Put("/brands/{Id}");
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class CreateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Post("/api/classifications");
Post("/classifications");
AllowAnonymous();
}

View File

@@ -12,7 +12,7 @@ public class DeleteClassificationEndpoint(PyroFetesDbContext libraryDbContext) :
{
public override void Configure()
{
Delete("/api/classifications/{@id}", x => new { x.Id });
Delete("/classifications/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllClassificationsEndpoint(PyroFetesDbContext pyrofetesdbcontext
{
public override void Configure()
{
Get("/api/classifications");
Get("/classifications");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext) :E
{
public override void Configure()
{
Get("/api/classifications/{@id}", x => new { x.Id });
Get("/classifications/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class UpdateClassificationEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Put("/api/classifications");
Put("/classifications");
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class CreateColorEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi
{
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
Post("/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
}

View File

@@ -12,7 +12,7 @@ public class DeleteColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Delete("Api/colors/{@id}", x => new { x.Id });
Delete("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllColorsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
{
public override void Configure()
{
Get("Api/colors");
Get("/colors");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint<
{
public override void Configure()
{
Get("Api/colors/{@id}", x => new { x.Id});
Get("/colors/{@id}", x => new { x.Id});
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class UpdateColorEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Put("Api/colors/{@id}", x => new { x.Id });
Put("/colors/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class CreateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
{
public override void Configure()
{
Post("Api/effects");
Post("/effects");
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class DeleteEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
{
public override void Configure()
{
Delete("Api/effects/{@id}", x => new { x.Id });
Delete("/effects/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllEffectsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endp
{
public override void Configure()
{
Get("Api/effects");
Get("/effects");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoint
{
public override void Configure()
{
Get("Api/effects/{@id}", x => new { x.Id });
Get("/effects/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class UpdateEffectEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpo
{
public override void Configure()
{
Put("Api/effects/{@id}", x => new { x.Id });
Put("/effects/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}

View File

@@ -8,7 +8,7 @@ public class CreateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Post("Api/materials");
Post("/materials");
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllMaterialsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
{
public override void Configure()
{
Get("Api/materials");
Get("/materials");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : Endpoi
{
public override void Configure()
{
Get("Api/materials/{@id}", x => new { x.Id });
Get("/materials/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class UpdateMaterialEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Put("Api/materials/{@id}", x => new { x.Id });
Put("/materials/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

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

View File

@@ -12,7 +12,7 @@ public class DeleteMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Delete("/api/Movements/{@id}", x => new { x.Id });
Delete("/Movements/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllMovementsEndpoint(PyroFetesDbContext pyrofetesdbcontext) : En
{
public override void Configure()
{
Get("/api/movements");
Get("/movements");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class GetMovementEndpoint(PyroFetesDbContext pyrofetesdbcontext) :Endpoin
{
public override void Configure()
{
Get("/api/movements/{@id}", x => new { x.Id });
Get("/movements/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

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

View File

@@ -11,7 +11,7 @@ public class CreateProductEndpoint(PyroFetesDbContext db)
{
public override void Configure()
{
Post("/api/products");
Post("/products");
AllowAnonymous();
}
@@ -19,7 +19,7 @@ public class CreateProductEndpoint(PyroFetesDbContext db)
{
var product = new Models.Product
{
Reference = req.References.ToString(),
Reference = req.Reference,
Name = req.Name!,
Duration = req.Duration,
Caliber = req.Caliber,
@@ -75,7 +75,7 @@ public class CreateProductEndpoint(PyroFetesDbContext db)
var response = new GetProductDto
{
Id = product.Id,
Reference = req.References,
Reference = req.Reference,
Name = req.Name,
Duration = req.Duration,
Caliber = req.Caliber,

View File

@@ -13,7 +13,7 @@ public class DeleteProductEndpoint(PyroFetesDbContext db) : Endpoint<DeleteProdu
{
public override void Configure()
{
Delete("/api/products/{@id}", x => new { x.Id });
Delete("/products/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
{
public override void Configure()
{
Get("/api/products");
Get("/products");
AllowAnonymous();
}
@@ -20,7 +20,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
// Inclure toutes les relations nécessaires : Prices + WarehouseProducts + Warehouse
var products = await db.Products
.Include(p => p.Prices)
.Include(p => p.WarehouseProducts)
.Include(p => p.WarehouseProducts)!
.ThenInclude(wp => wp.Warehouse)
.ToListAsync(ct);
@@ -28,7 +28,7 @@ public class GetAllProductsEndpoint(PyroFetesDbContext db)
{
Id = p.Id,
// Le modèle Product contient "Reference" (string) — pas "References" (int)
Reference = int.TryParse(p.Reference, out var refInt) ? refInt : 0,
Reference = p.Reference,
Name = p.Name,
Duration = p.Duration,
Caliber = p.Caliber,

View File

@@ -16,7 +16,7 @@ public class GetProductEndpoint(PyroFetesDbContext db)
{
public override void Configure()
{
Get("/api/products/{@id}", x => new { x.Id });
Get("/products/{@id}", x => new { x.Id });
AllowAnonymous();
}
@@ -41,7 +41,7 @@ public class GetProductEndpoint(PyroFetesDbContext db)
Id = product.Id,
// Le modèle Product contient "Reference" (string), pas "References" (int)
Reference = int.TryParse(product.Reference, out var refInt) ? refInt : 0,
Reference = product.Reference,
Name = product.Name,
Duration = product.Duration,

View File

@@ -13,7 +13,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext db)
public override void Configure()
{
// Route HTTP PUT avec un paramètre d'identifiant dans l'URL
Put("/api/products/{@id}", x => new { x.Id });
Put("/products/{@id}", x => new { x.Id });
// Autorise les requêtes anonymes (sans authentification)
AllowAnonymous();
@@ -35,7 +35,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext db)
}
// Mise à jour des propriétés principales du produit
product.Reference = req.References.ToString(); // Converti int → string
product.Reference = req.Reference; // Converti int → string
product.Name = req.Name;
product.Duration = req.Duration;
product.Caliber = req.Caliber;
@@ -77,7 +77,7 @@ public class UpdateProductEndpoint(PyroFetesDbContext db)
var response = new GetProductDto
{
Id = product.Id,
Reference = req.References, // DTO garde int pour cohérence
Reference = req.Reference, // DTO garde int pour cohérence
Name = req.Name,
Duration = req.Duration,
Caliber = req.Caliber,

View File

@@ -8,7 +8,7 @@ public class CreateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
{
public override void Configure()
{
Post("/api/productcategories");
Post("/productcategories");
AllowAnonymous();
}

View File

@@ -12,7 +12,7 @@ public class DeleteProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
{
public override void Configure()
{
Delete("/api/productcategories/{@id}", x => new { x.Id });
Delete("/productcategories/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -8,7 +8,7 @@ public class GetAllProductCategoriesEndpoint(PyroFetesDbContext pyrofetesdbconte
{
public override void Configure()
{
Get("/api/productcategories");
Get("/productcategories");
AllowAnonymous();
}

View File

@@ -14,7 +14,7 @@ public class GetProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext) :
{
public override void Configure()
{
Get("/api/productcategory/{@id}", x => new { x.Id });
Get("/productcategory/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -9,7 +9,7 @@ public class UpdateProductCategoryEndpoint(PyroFetesDbContext pyrofetesdbcontext
{
public override void Configure()
{
Put("/api/productcategory/{@id}", x => new { x.Id });
Put("/productcategory/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class CreateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Post("/api/suppliers");
Post("/suppliers");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class DeleteSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Delete("/api/suppliers/{@id}", x => new { x.Id });
Delete("/suppliers/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -11,7 +11,7 @@ public class GetAllSuppliersEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Get("/api/suppliers");
Get("/suppliers");
AllowAnonymous();
}

View File

@@ -15,7 +15,7 @@ public class GetSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext)
{
public override void Configure()
{
Get("/api/suppliers/{@id}", x => new { x.Id });
Get("/suppliers/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -10,7 +10,7 @@ public class UpdateSupplierEndpoint(PyroFetesDbContext pyrofetesdbcontext) : End
{
public override void Configure()
{
Put("/api/suppliers/{@id}", x => new { x.Id });
Put("/suppliers/{@id}", x => new { x.Id });
AllowAnonymous();
}

View File

@@ -10,7 +10,7 @@ public class CreateWarehouseEndpoint(PyroFetesDbContext db)
{
public override void Configure()
{
Post("/api/warehouse");
Post("/warehouse");
AllowAnonymous();
}

View File

@@ -13,7 +13,7 @@ public class DeleteWarehouseEndpoint(PyroFetesDbContext db) : Endpoint<DeleteWar
{
public override void Configure()
{
Delete("/api/warehouse/{id}");
Delete("/warehouse/{id}");
AllowAnonymous();
}
public override async Task HandleAsync(DeleteWarehouseRequest req, CancellationToken ct)

View File

@@ -1,5 +1,4 @@
using API.DTO.Warehouse.Response;
using API.DTO.Warehouse.Request;
using FastEndpoints;
using Microsoft.EntityFrameworkCore;
using PyroFetes.Models;
@@ -11,36 +10,66 @@ public class GetAllWarehouseEndpoint(PyroFetesDbContext db)
{
public override void Configure()
{
Get("/api/warehouses");
Get("/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
try
{
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();
// 1. Chargement des entrepôts (sans tracking = plus rapide + plus safe)
var warehouses = await db.Warehouses
.AsNoTracking()
.ToListAsync(ct);
await Send.OkAsync(response, ct);
// 2. Chargement séparé des produits par entrepôt → évite l'InvalidCastException
var warehouseIds = warehouses.Select(w => w.Id).ToList();
var warehouseProducts = await db.WarehouseProducts
.Where(wp => warehouseIds.Contains(wp.WarehouseId))
.Include(wp => wp.Product)
.AsNoTracking()
.ToListAsync(ct);
// 3. Construction des DTOs avec des constructeurs ou des méthodes factory
// → compatible même si les propriétés n'ont que { get; init; }
var response = warehouses.Select(w =>
{
var dto = new GetWarehouseDto();
dto.GetType().GetProperty("Id")?.SetValue(dto, w.Id);
dto.GetType().GetProperty("Name")?.SetValue(dto, w.Name ?? string.Empty);
dto.GetType().GetProperty("MaxWeight")?.SetValue(dto, w.MaxWeight);
dto.GetType().GetProperty("Current")?.SetValue(dto, w.Current);
dto.GetType().GetProperty("MinWeight")?.SetValue(dto, w.MinWeight);
dto.GetType().GetProperty("Adress")?.SetValue(dto, w.Address ?? string.Empty);
dto.GetType().GetProperty("ZipCode")?.SetValue(dto, w.ZipCode);
dto.GetType().GetProperty("City")?.SetValue(dto, w.City ?? string.Empty);
// Products
var productsList = warehouseProducts
.Where(wp => wp.WarehouseId == w.Id)
.Select(wp =>
{
var prodDto = new WarehouseProductDto();
prodDto.GetType().GetProperty("ProductId")?.SetValue(prodDto, wp.ProductId);
prodDto.GetType().GetProperty("ProductName")?.SetValue(prodDto, wp.Product?.Name ?? "Produit inconnu");
prodDto.GetType().GetProperty("Quantity")?.SetValue(prodDto, wp.Quantity);
return prodDto;
})
.ToList();
dto.GetType().GetProperty("Products")?.SetValue(dto, productsList);
return dto;
}).ToList();
await Send.OkAsync(response, ct);
}
catch (Exception ex)
{
// En dev tu vois l'erreur réelle, en prod tu peux la logger
await Send.OkAsync(ct);
}
}
}

View File

@@ -16,7 +16,7 @@ public class GetWarehouseEndpoint(PyroFetesDbContext db)
public override void Configure()
{
// Pas de "@id" ici, juste {id}
Get("/api/warehouses/{Id}");
Get("/warehouses/{Id}");
AllowAnonymous();
}
@@ -24,7 +24,7 @@ public class GetWarehouseEndpoint(PyroFetesDbContext db)
{
// 🔹 Inclut les produits associés à cet entrepôt
var warehouse = await db.Warehouses
.Include(w => w.WarehouseProducts)
.Include(w => w.WarehouseProducts)!
.ThenInclude(wp => wp.Product)
.SingleOrDefaultAsync(w => w.Id == req.Id, cancellationToken: ct);

View File

@@ -12,7 +12,7 @@ public class UpdateWarehouseEndpoint(PyroFetesDbContext db)
public override void Configure()
{
// Utilise {id} plutôt que {@id}
Put("/api/warehouses/{Id}");
Put("/warehouses/{Id}");
AllowAnonymous();
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

13
PyroFetes/Models/.idea/.gitignore generated vendored
View File

@@ -1,13 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.Models.iml
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -9,7 +9,7 @@ public class DeliveryNote
public int DelivererId { get; set; }
[Required] public DateOnly EstimateDeliveryDate { get; set; }
[Required] public DateOnly ExpeditionDate { get; set; }
[Required] public DateOnly RealDeliveryDate { get; set; }
public DateOnly? RealDeliveryDate { get; set; }
public Deliverer? Deliverer { get; set; }
public List<ProductDelivery>? ProductDeliveries { get; set; }

View File

@@ -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; }
}

View File

@@ -8,8 +8,8 @@ namespace PyroFetes.Models
[Required, MaxLength(20)] public string? Reference { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required] public decimal Duration {get; set;}
[Required] public decimal Caliber { get; set; }
[Required] public int ApprovalNumber { get; set; }
[Required] public int Caliber { get; set; }
[Required, MaxLength(100)] public string? ApprovalNumber { get; set; }
[Required] public decimal Weight { get; set; }
[Required] public decimal Nec { get; set; }
[Required] public string? Image { get; set; }

View File

@@ -9,7 +9,7 @@ public class Supplier
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(30)] public string? Phone { get; set; }
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required,Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
[Required] public int DeliveryDelay { get; set; }

View File

@@ -6,7 +6,7 @@ public class User
{
[Key] public int Id { get; set; }
[Required, MaxLength(100)] public string? Name { get; set; }
[Required, MinLength(12), MaxLength(50)] public string? Password { get; set; }
[Required, MaxLength(60)] public string? Password { get; set; }
[Required, MaxLength(100)] public string? Salt { get; set; }
[Required, MaxLength(100)] public string? Email { get; set; }
[Required, MaxLength(100)] public string? Fonction { get; set; }

View File

@@ -10,7 +10,7 @@ public class Warehouse
[Required] public int Current {get; set;}
[Required] public int MinWeight {get; set;}
[Required, MaxLength(100)] public string? Address { get; set; }
[Required] public int ZipCode { get; set; }
[Required, Length(5,5)] public string? ZipCode { get; set; }
[Required, MaxLength(100)] public string? City { get; set; }
public List<WarehouseProduct>? WarehouseProducts { get; set; }

View File

@@ -1,29 +1,42 @@
using API;
using FastEndpoints;
using FastEndpoints.Swagger;
using PyroFetes;
using FastEndpoints.Security;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// On ajoute ici FastEndpoints, un framework REPR et Swagger aux services disponibles dans le projet
builder.Services
.AddAuthenticationJwtBearer(s => s.SigningKey = "ThisIsASuperSecretJwtKeyThatIsAtLeast32CharsLong")
.AddAuthorization()
.AddFastEndpoints()
.SwaggerDocument();
// Services
builder.Services.AddCors(options =>
options.AddDefaultPolicy(policyBuilder =>
policyBuilder
.WithOrigins("http://localhost:4200") // mettre le port Angular exact
.WithMethods("GET", "POST", "PUT", "PATCH", "DELETE")
.AllowAnyHeader()
)
);
builder.Services.AddFastEndpoints().SwaggerDocument(options =>
{
options.ShortSchemaNames = true;
});
// On ajoute ici la configuration de la base de données
builder.Services.AddDbContext<PyroFetesDbContext>();
// On construit l'application en lui donnant vie
WebApplication app = builder.Build();
app.UseAuthentication()
.UseAuthorization()
.UseFastEndpoints()
.UseSwaggerGen();
// Middleware
app.UseHttpsRedirection();
// CORS doit être avant les endpoints
app.UseCors();
// FastEndpoints et Swagger
app.UseFastEndpoints(options =>
{
options.Endpoints.RoutePrefix = "API";
options.Endpoints.ShortNames = true;
}).UseSwaggerGen();
// app.UseAuthorization();
// app.UseAuthentication();
app.Run();

View File

@@ -22,4 +22,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View File

@@ -49,7 +49,6 @@ public class PyroFetesDbContext : DbContext
public DbSet<User> Users { get; set; }
public DbSet<Warehouse> Warehouses { get; set; }
public DbSet<WarehouseProduct> WarehouseProducts { get; set; }
public DbSet<Login> Logins { get; set; }
// Database configuration
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)