From f60d3443ca967c18af1e2c1462b1ba48c089fd0a Mon Sep 17 00:00:00 2001 From: oistig Date: Thu, 27 Nov 2025 15:00:53 +0100 Subject: [PATCH] =?UTF-8?q?r=C3=A9paration=20des=20models=20et=20correctio?= =?UTF-8?q?ns=20du=20type=20caliber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/Login/Request/ConnectLoginDto.cs | 7 --- PyroFetes/DTO/Login/Request/CreateLoginDto.cs | 8 --- PyroFetes/DTO/Login/Request/UpdateLoginDto.cs | 9 ---- .../DTO/Login/Response/GetLoginConnectDto.cs | 6 --- PyroFetes/DTO/Login/Response/GetLoginDto.cs | 10 ---- .../DTO/Product/Request/CreateProductDto.cs | 2 +- .../DTO/Product/Request/UpdateProductDto.cs | 2 +- .../DTO/Product/Response/GetProductDto.cs | 2 +- .../Endpoints/Login/CreateLoginEndpoint.cs | 44 ---------------- .../Endpoints/Login/DeleteLoginEndpoint.cs | 35 ------------- .../Endpoints/Login/GetAllLoginEndpoint.cs | 30 ----------- PyroFetes/Endpoints/Login/GetLoginEndpoint.cs | 41 --------------- .../Endpoints/Login/UpdateLoginEndpoint.cs | 45 ----------------- .../Endpoints/Login/UserLoginEndpoint.cs | 50 ------------------- PyroFetes/Models/.idea/.gitignore | 13 ----- PyroFetes/Models/.idea/encodings.xml | 4 -- PyroFetes/Models/.idea/indexLayout.xml | 8 --- PyroFetes/Models/DeliveryNote.cs | 2 +- PyroFetes/Models/Login.cs | 13 ----- PyroFetes/Models/Product.cs | 4 +- PyroFetes/Models/Supplier.cs | 2 +- PyroFetes/Models/User.cs | 2 +- PyroFetes/Models/Warehouse.cs | 2 +- PyroFetes/PyroFetesDbContext.cs | 1 - 24 files changed, 9 insertions(+), 333 deletions(-) delete mode 100644 PyroFetes/DTO/Login/Request/ConnectLoginDto.cs delete mode 100644 PyroFetes/DTO/Login/Request/CreateLoginDto.cs delete mode 100644 PyroFetes/DTO/Login/Request/UpdateLoginDto.cs delete mode 100644 PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs delete mode 100644 PyroFetes/DTO/Login/Response/GetLoginDto.cs delete mode 100644 PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs delete mode 100644 PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs delete mode 100644 PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs delete mode 100644 PyroFetes/Endpoints/Login/GetLoginEndpoint.cs delete mode 100644 PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs delete mode 100644 PyroFetes/Endpoints/Login/UserLoginEndpoint.cs delete mode 100644 PyroFetes/Models/.idea/.gitignore delete mode 100644 PyroFetes/Models/.idea/encodings.xml delete mode 100644 PyroFetes/Models/.idea/indexLayout.xml delete mode 100644 PyroFetes/Models/Login.cs diff --git a/PyroFetes/DTO/Login/Request/ConnectLoginDto.cs b/PyroFetes/DTO/Login/Request/ConnectLoginDto.cs deleted file mode 100644 index 19dc9f0..0000000 --- a/PyroFetes/DTO/Login/Request/ConnectLoginDto.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace PyroFetes.DTO.Login.Request; - -public class ConnectLoginDto -{ - public string? Username { get; set; } - public string? Password { get; set; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/Login/Request/CreateLoginDto.cs b/PyroFetes/DTO/Login/Request/CreateLoginDto.cs deleted file mode 100644 index 7576655..0000000 --- a/PyroFetes/DTO/Login/Request/CreateLoginDto.cs +++ /dev/null @@ -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; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/Login/Request/UpdateLoginDto.cs b/PyroFetes/DTO/Login/Request/UpdateLoginDto.cs deleted file mode 100644 index 54f8ccf..0000000 --- a/PyroFetes/DTO/Login/Request/UpdateLoginDto.cs +++ /dev/null @@ -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; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs b/PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs deleted file mode 100644 index 6ae4c01..0000000 --- a/PyroFetes/DTO/Login/Response/GetLoginConnectDto.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PyroFetes.DTO.Login.Response; - -public class GetLoginConnectDto -{ - public string? Token { get; set; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/Login/Response/GetLoginDto.cs b/PyroFetes/DTO/Login/Response/GetLoginDto.cs deleted file mode 100644 index 300724e..0000000 --- a/PyroFetes/DTO/Login/Response/GetLoginDto.cs +++ /dev/null @@ -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; } -} \ No newline at end of file diff --git a/PyroFetes/DTO/Product/Request/CreateProductDto.cs b/PyroFetes/DTO/Product/Request/CreateProductDto.cs index 5922772..c85c545 100644 --- a/PyroFetes/DTO/Product/Request/CreateProductDto.cs +++ b/PyroFetes/DTO/Product/Request/CreateProductDto.cs @@ -15,7 +15,7 @@ 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 d’homologation public string? ApprovalNumber { get; set; } diff --git a/PyroFetes/DTO/Product/Request/UpdateProductDto.cs b/PyroFetes/DTO/Product/Request/UpdateProductDto.cs index 56e1338..29e48e3 100644 --- a/PyroFetes/DTO/Product/Request/UpdateProductDto.cs +++ b/PyroFetes/DTO/Product/Request/UpdateProductDto.cs @@ -18,7 +18,7 @@ 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 d’homologation public string? ApprovalNumber { get; set; } diff --git a/PyroFetes/DTO/Product/Response/GetProductDto.cs b/PyroFetes/DTO/Product/Response/GetProductDto.cs index 53016fb..d6d6828 100644 --- a/PyroFetes/DTO/Product/Response/GetProductDto.cs +++ b/PyroFetes/DTO/Product/Response/GetProductDto.cs @@ -19,7 +19,7 @@ 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 d’homologation public string? ApprovalNumber { get; set; } diff --git a/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs b/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs deleted file mode 100644 index 6fefac4..0000000 --- a/PyroFetes/Endpoints/Login/CreateLoginEndpoint.cs +++ /dev/null @@ -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 -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs b/PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs deleted file mode 100644 index 73fdfd8..0000000 --- a/PyroFetes/Endpoints/Login/DeleteLoginEndpoint.cs +++ /dev/null @@ -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 -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs b/PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs deleted file mode 100644 index 4d35151..0000000 --- a/PyroFetes/Endpoints/Login/GetAllLoginEndpoint.cs +++ /dev/null @@ -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> -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/GetLoginEndpoint.cs b/PyroFetes/Endpoints/Login/GetLoginEndpoint.cs deleted file mode 100644 index 04cb70a..0000000 --- a/PyroFetes/Endpoints/Login/GetLoginEndpoint.cs +++ /dev/null @@ -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 -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs b/PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs deleted file mode 100644 index ef36a19..0000000 --- a/PyroFetes/Endpoints/Login/UpdateLoginEndpoint.cs +++ /dev/null @@ -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 -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Endpoints/Login/UserLoginEndpoint.cs b/PyroFetes/Endpoints/Login/UserLoginEndpoint.cs deleted file mode 100644 index bdad4e6..0000000 --- a/PyroFetes/Endpoints/Login/UserLoginEndpoint.cs +++ /dev/null @@ -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 -{ - 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); - } -} \ No newline at end of file diff --git a/PyroFetes/Models/.idea/.gitignore b/PyroFetes/Models/.idea/.gitignore deleted file mode 100644 index 516c578..0000000 --- a/PyroFetes/Models/.idea/.gitignore +++ /dev/null @@ -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 diff --git a/PyroFetes/Models/.idea/encodings.xml b/PyroFetes/Models/.idea/encodings.xml deleted file mode 100644 index df87cf9..0000000 --- a/PyroFetes/Models/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PyroFetes/Models/.idea/indexLayout.xml b/PyroFetes/Models/.idea/indexLayout.xml deleted file mode 100644 index 7b08163..0000000 --- a/PyroFetes/Models/.idea/indexLayout.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/PyroFetes/Models/DeliveryNote.cs b/PyroFetes/Models/DeliveryNote.cs index 21e873e..e94792f 100644 --- a/PyroFetes/Models/DeliveryNote.cs +++ b/PyroFetes/Models/DeliveryNote.cs @@ -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? ProductDeliveries { get; set; } diff --git a/PyroFetes/Models/Login.cs b/PyroFetes/Models/Login.cs deleted file mode 100644 index 89b7eaf..0000000 --- a/PyroFetes/Models/Login.cs +++ /dev/null @@ -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; } -} diff --git a/PyroFetes/Models/Product.cs b/PyroFetes/Models/Product.cs index 66fcf1e..88f52e4 100644 --- a/PyroFetes/Models/Product.cs +++ b/PyroFetes/Models/Product.cs @@ -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 string? 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; } diff --git a/PyroFetes/Models/Supplier.cs b/PyroFetes/Models/Supplier.cs index 9ed69ce..539b1b4 100644 --- a/PyroFetes/Models/Supplier.cs +++ b/PyroFetes/Models/Supplier.cs @@ -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 string? 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; } diff --git a/PyroFetes/Models/User.cs b/PyroFetes/Models/User.cs index 8baaa1c..18b181e 100644 --- a/PyroFetes/Models/User.cs +++ b/PyroFetes/Models/User.cs @@ -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; } diff --git a/PyroFetes/Models/Warehouse.cs b/PyroFetes/Models/Warehouse.cs index 86ac934..d1e6420 100644 --- a/PyroFetes/Models/Warehouse.cs +++ b/PyroFetes/Models/Warehouse.cs @@ -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 string? ZipCode { get; set; } + [Required, Length(5,5)] public string? ZipCode { get; set; } [Required, MaxLength(100)] public string? City { get; set; } public List? WarehouseProducts { get; set; } diff --git a/PyroFetes/PyroFetesDbContext.cs b/PyroFetes/PyroFetesDbContext.cs index b4958b2..b5ce8c7 100644 --- a/PyroFetes/PyroFetesDbContext.cs +++ b/PyroFetes/PyroFetesDbContext.cs @@ -49,7 +49,6 @@ public class PyroFetesDbContext : DbContext public DbSet Users { get; set; } public DbSet Warehouses { get; set; } public DbSet WarehouseProducts { get; set; } - public DbSet Logins { get; set; } // Database configuration protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)