From 6c1330e570080bce7c3d652c9a9a90667a829870 Mon Sep 17 00:00:00 2001 From: timothe Date: Wed, 27 May 2026 19:35:01 +0200 Subject: [PATCH] Fix FastEndpoints/Swagger wiring and missing required fields in DTOs - Register FastEndpoints, SwaggerDocument, DbContext in Program.cs - Add DbContextOptions constructor to PyroFetesDbContext - Add CityId to Show DTOs and endpoints (NOT NULL in DB) - Add F4T2NumberApproval/F4T2ExpirationDate to Staff DTOs and endpoints - Simplify DeleteShow to rely on DB cascade instead of manual includes - Default NOT NULL string fields to empty string on create Co-Authored-By: Claude Sonnet 4.6 --- PyroFetes/DTO/Show/Request/CreateShowDto.cs | 1 + PyroFetes/DTO/Show/Request/UpdateShowDto.cs | 1 + PyroFetes/DTO/Show/Response/ReadShowDto.cs | 1 + PyroFetes/DTO/Staff/Request/CreateStaffDto.cs | 2 ++ PyroFetes/DTO/Staff/Request/UpdateStaffDto.cs | 2 ++ PyroFetes/DTO/Staff/Response/ReadStaffDto.cs | 2 ++ .../Endpoints/Show/CreateShowEndpoint.cs | 12 +++++----- .../Endpoints/Show/DeleteShowEndpoint.cs | 16 -------------- .../Endpoints/Show/GetAllShowsEndpoint.cs | 3 ++- PyroFetes/Endpoints/Show/GetShowEndpoint.cs | 3 ++- .../Endpoints/Show/UpdateShowEndpoint.cs | 10 ++++----- .../Endpoints/Staff/CreateStaffEndpoint.cs | 18 +++++++++------ .../Endpoints/Staff/GetAllStaffEndpoint.cs | 4 +++- PyroFetes/Endpoints/Staff/GetStaffEndpoint.cs | 4 +++- .../Endpoints/Staff/UpdateStaffEndpoint.cs | 15 ++++++++----- PyroFetes/Program.cs | 22 ++++++++++++------- PyroFetes/PyroFetesDbContext.cs | 2 +- PyroFetes/appsettings.json | 5 ++++- 18 files changed, 70 insertions(+), 53 deletions(-) diff --git a/PyroFetes/DTO/Show/Request/CreateShowDto.cs b/PyroFetes/DTO/Show/Request/CreateShowDto.cs index 5dcb292..05e62b7 100644 --- a/PyroFetes/DTO/Show/Request/CreateShowDto.cs +++ b/PyroFetes/DTO/Show/Request/CreateShowDto.cs @@ -7,4 +7,5 @@ public class CreateShowDto public string? Description { get; set; } public string? PyrotechnicImplementationPlan { get; set; } public DateTime? Date { get; set; } + public int CityId { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Show/Request/UpdateShowDto.cs b/PyroFetes/DTO/Show/Request/UpdateShowDto.cs index 25b68e3..beb8aaf 100644 --- a/PyroFetes/DTO/Show/Request/UpdateShowDto.cs +++ b/PyroFetes/DTO/Show/Request/UpdateShowDto.cs @@ -8,4 +8,5 @@ public class UpdateShowDto public string? Description { get; set; } public string? PyrotechnicImplementationPlan { get; set; } public DateTime? Date { get; set; } + public int? CityId { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Show/Response/ReadShowDto.cs b/PyroFetes/DTO/Show/Response/ReadShowDto.cs index 41ceec4..c9a6250 100644 --- a/PyroFetes/DTO/Show/Response/ReadShowDto.cs +++ b/PyroFetes/DTO/Show/Response/ReadShowDto.cs @@ -8,4 +8,5 @@ public class ReadShowDto public string? Description { get; set; } public string? PyrotechnicImplementationPlan { get; set; } public DateTime? Date { get; set; } + public int CityId { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Staff/Request/CreateStaffDto.cs b/PyroFetes/DTO/Staff/Request/CreateStaffDto.cs index 4189bcd..a5b936f 100644 --- a/PyroFetes/DTO/Staff/Request/CreateStaffDto.cs +++ b/PyroFetes/DTO/Staff/Request/CreateStaffDto.cs @@ -6,4 +6,6 @@ public class CreateStaffDto public string? LastName { get; set; } public string? Profession { get; set; } public string? Email { get; set; } + public string? F4T2NumberApproval { get; set; } + public DateOnly F4T2ExpirationDate { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Staff/Request/UpdateStaffDto.cs b/PyroFetes/DTO/Staff/Request/UpdateStaffDto.cs index 549b146..8c08099 100644 --- a/PyroFetes/DTO/Staff/Request/UpdateStaffDto.cs +++ b/PyroFetes/DTO/Staff/Request/UpdateStaffDto.cs @@ -7,4 +7,6 @@ public class UpdateStaffDto public string? LastName { get; set; } public string? Profession { get; set; } public string? Email { get; set; } + public string? F4T2NumberApproval { get; set; } + public DateOnly? F4T2ExpirationDate { get; set; } } \ No newline at end of file diff --git a/PyroFetes/DTO/Staff/Response/ReadStaffDto.cs b/PyroFetes/DTO/Staff/Response/ReadStaffDto.cs index 383be4a..38780ee 100644 --- a/PyroFetes/DTO/Staff/Response/ReadStaffDto.cs +++ b/PyroFetes/DTO/Staff/Response/ReadStaffDto.cs @@ -7,4 +7,6 @@ public class ReadStaffDto public string? LastName { get; set; } public string? Profession { get; set; } public string? Email { get; set; } + public string? F4T2NumberApproval { get; set; } + public DateOnly F4T2ExpirationDate { get; set; } } \ No newline at end of file diff --git a/PyroFetes/Endpoints/Show/CreateShowEndpoint.cs b/PyroFetes/Endpoints/Show/CreateShowEndpoint.cs index 7234f1e..d3b2133 100644 --- a/PyroFetes/Endpoints/Show/CreateShowEndpoint.cs +++ b/PyroFetes/Endpoints/Show/CreateShowEndpoint.cs @@ -16,11 +16,12 @@ public class CreateShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoin { var show = new PyroFetes.Models.Show { - Name = req.Name, - Place = req.Place, + Name = req.Name ?? string.Empty, + Place = req.Place ?? string.Empty, Description = req.Description, - PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan, - Date = req.Date.HasValue ? DateOnly.FromDateTime(req.Date.Value) : null + PyrotechnicImplementationPlan = req.PyrotechnicImplementationPlan ?? string.Empty, + Date = req.Date.HasValue ? DateOnly.FromDateTime(req.Date.Value) : null, + CityId = req.CityId }; pyroFetesDbContext.Shows.Add(show); @@ -33,7 +34,8 @@ public class CreateShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoin Place = show.Place, Description = show.Description, PyrotechnicImplementationPlan = show.PyrotechnicImplementationPlan, - Date = show.Date.HasValue ? show.Date.Value.ToDateTime(TimeOnly.MinValue) : null + Date = show.Date.HasValue ? show.Date.Value.ToDateTime(TimeOnly.MinValue) : null, + CityId = show.CityId }; await Send.OkAsync(result, ct); diff --git a/PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs b/PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs index c1fe117..d31723c 100644 --- a/PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs +++ b/PyroFetes/Endpoints/Show/DeleteShowEndpoint.cs @@ -21,12 +21,6 @@ public class DeleteShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoin } var show = await pyroFetesDbContext.Shows - .Include(s => s.ShowTrucks) - .Include(s => s.ShowStaffs) - .Include(s => s.SoundTimecodes) - .Include(s => s.ProductTimecodes) - .Include(s => s.Contracts) - .Include(s => s.ShowMaterials) .FirstOrDefaultAsync(s => s.Id == req.Id.Value, ct); if (show is null) @@ -35,16 +29,6 @@ public class DeleteShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoin return; } - // Supprimer les relations associées - if (show.ShowTrucks != null && show.ShowTrucks.Any()) - { - pyroFetesDbContext.ShowTrucks.RemoveRange(show.ShowTrucks); - } - - // Note: Les autres relations (ShowStaffs, SoundTimecodes, etc.) devront aussi être gérées - // en fonction de votre modèle de données et de vos règles métier - // Pour l'instant, je laisse juste ShowTrucks comme exemple - pyroFetesDbContext.Shows.Remove(show); await pyroFetesDbContext.SaveChangesAsync(ct); diff --git a/PyroFetes/Endpoints/Show/GetAllShowsEndpoint.cs b/PyroFetes/Endpoints/Show/GetAllShowsEndpoint.cs index 917bc9d..111a87c 100644 --- a/PyroFetes/Endpoints/Show/GetAllShowsEndpoint.cs +++ b/PyroFetes/Endpoints/Show/GetAllShowsEndpoint.cs @@ -22,7 +22,8 @@ public class GetAllShowsEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoi Place = s.Place, Description = s.Description, PyrotechnicImplementationPlan = s.PyrotechnicImplementationPlan, - Date = s.Date.HasValue ? s.Date.Value.ToDateTime(TimeOnly.MinValue) : null + Date = s.Date.HasValue ? s.Date.Value.ToDateTime(TimeOnly.MinValue) : null, + CityId = s.CityId }) .ToListAsync(ct); diff --git a/PyroFetes/Endpoints/Show/GetShowEndpoint.cs b/PyroFetes/Endpoints/Show/GetShowEndpoint.cs index 8675f2f..ab11d04 100644 --- a/PyroFetes/Endpoints/Show/GetShowEndpoint.cs +++ b/PyroFetes/Endpoints/Show/GetShowEndpoint.cs @@ -30,7 +30,8 @@ public class GetShowEndpoint(PyroFetesDbContext pyroFetesDbContext) : Endpoint(options => + options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); + +builder.Services.AddFastEndpoints(); +builder.Services.SwaggerDocument(); var app = builder.Build(); -// Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerGen(); } app.UseHttpsRedirection(); +app.UseFastEndpoints(); -app.Run(); \ No newline at end of file +app.Run(); + \ No newline at end of file diff --git a/PyroFetes/PyroFetesDbContext.cs b/PyroFetes/PyroFetesDbContext.cs index 996befa..468b795 100644 --- a/PyroFetes/PyroFetesDbContext.cs +++ b/PyroFetes/PyroFetesDbContext.cs @@ -4,7 +4,7 @@ using ServiceProvider = PyroFetes.Models.ServiceProvider; namespace PyroFetes; -public class PyroFetesDbContext : DbContext +public class PyroFetesDbContext(DbContextOptions options) : DbContext(options) { // Entities public DbSet Availabilities { get; set; } diff --git a/PyroFetes/appsettings.json b/PyroFetes/appsettings.json index 10f68b8..dac588a 100644 --- a/PyroFetes/appsettings.json +++ b/PyroFetes/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Server=romaric-thibault.fr;Database=PyroFetes;Trusted_Connection=True;TrustServerCertificate=True;" + } }