From e27e2864f40dce61934d63dfa4fa4199d01a1856 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 19:25:15 +0200 Subject: [PATCH 1/7] #199 : Modification de l'ajout de commentaire. --- .../Controllers/TitreController.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index fbab2ae..07caf80 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -20,16 +20,23 @@ namespace Webzine.WebApplication.Controllers private readonly ILogger logger; private readonly ITitreRepository titreRepository; + // Pour les commentaires. + private readonly ICommentaireRepository commentaireRepository; + /// /// Initializes a new instance of the class. /// Initialise une nouvelle instance de la classe . /// /// Service de journalisation injecte. /// Repository des titres injecte. - public TitreController(ILogger logger, ITitreRepository titreRepository) + public TitreController( + ILogger logger, + ITitreRepository titreRepository, + ICommentaireRepository commentaireRepository) { this.logger = logger; this.titreRepository = titreRepository; + this.commentaireRepository = commentaireRepository; this.logger.LogInformation("Initialisation du controleur TitreController."); } @@ -101,19 +108,19 @@ namespace Webzine.WebApplication.Controllers [HttpPost] public IActionResult Comment([Bind(Prefix = "CommentForm")] TitreComment model) { + var titreToUpdate = this.titreRepository.Find(model.IdTitre); + if (!this.ModelState.IsValid) { - var titre = this.titreRepository.Find(model.IdTitre); - if (titre == null) + if (titreToUpdate == null) { this.logger.LogWarning("Titre avec ID {Id} introuvable pour ajout de commentaire.", model.IdTitre); return this.RedirectToAction("Index", "Accueil"); } - return this.View("Index", this.BuildTitreDetailViewModel(titre, model)); + return this.View("Index", this.BuildTitreDetailViewModel(titreToUpdate, model)); } - var titreToUpdate = this.titreRepository.Find(model.IdTitre); if (titreToUpdate != null) { var commentaire = new Commentaire @@ -124,8 +131,7 @@ namespace Webzine.WebApplication.Controllers IdTitre = model.IdTitre, }; - titreToUpdate.Commentaires.Add(commentaire); - this.titreRepository.Update(titreToUpdate); + this.commentaireRepository.Add(commentaire); } return this.RedirectToAction("Index", new { id = model.IdTitre }); From 937bfb56737df55cf200be5d4d96f4eb09003601 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 20:14:13 +0200 Subject: [PATCH 2/7] #199 : Modification du format de date pour la base postgresql. --- Webzine.WebApplication/Controllers/TitreController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index 07caf80..e4e8d67 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -123,11 +123,15 @@ namespace Webzine.WebApplication.Controllers if (titreToUpdate != null) { + var utcNow = DateTime.UtcNow; + var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Paris"); + var localTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, timeZone); + var commentaire = new Commentaire { Auteur = model.Auteur, Contenu = model.Contenu, - DateCreation = DateTime.Now, + DateCreation = localTime, IdTitre = model.IdTitre, }; From 6610094d168d70d400671bb556f58525928c2b29 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 20:36:30 +0200 Subject: [PATCH 3/7] #199 : Test de correction pour postgre. --- Webzine.Repository/DbCommentaireRepository.cs | 16 +++++++++++- .../Filters/GlobalExceptionFilter.cs | 25 ++++++++++++++++--- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Webzine.Repository/DbCommentaireRepository.cs b/Webzine.Repository/DbCommentaireRepository.cs index 7d669b2..8224f72 100644 --- a/Webzine.Repository/DbCommentaireRepository.cs +++ b/Webzine.Repository/DbCommentaireRepository.cs @@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Npgsql; + using Webzine.EntitiesContext; using Webzine.Entity; using Webzine.Repository.Contracts; @@ -38,7 +40,19 @@ public class DbCommentaireRepository : ICommentaireRepository } catch (DbUpdateException dbex) { - this.logger.LogError(dbex, "Erreur de base de données lors de l'ajout du commentaire de l'auteur : {Auteur}", commentaire?.Auteur); + PostgresException? postgresException = dbex.InnerException as PostgresException; + + this.logger.LogError( + dbex, + "Erreur de base de données lors de l'ajout du commentaire. Auteur: {Auteur} | IdTitre: {IdTitre} | DateCreation: {DateCreation:o} | PostgresCode: {PostgresCode} | Detail: {Detail} | Constraint: {Constraint} | Column: {Column} | Table: {Table}", + commentaire?.Auteur, + commentaire?.IdTitre, + commentaire?.DateCreation, + postgresException?.SqlState, + postgresException?.Detail, + postgresException?.ConstraintName, + postgresException?.ColumnName, + postgresException?.TableName); throw; } catch (Exception ex) diff --git a/Webzine.WebApplication/Filters/GlobalExceptionFilter.cs b/Webzine.WebApplication/Filters/GlobalExceptionFilter.cs index 15f9b73..8839d74 100644 --- a/Webzine.WebApplication/Filters/GlobalExceptionFilter.cs +++ b/Webzine.WebApplication/Filters/GlobalExceptionFilter.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; /// -/// Filtre d'exception global qui intercepte toute exception non gérée et la journalise automatiquement. +/// Filtre d'exception global qui intercepte toute exception non geree et la journalise automatiquement. /// public class GlobalExceptionFilter : IExceptionFilter { @@ -13,7 +13,7 @@ public class GlobalExceptionFilter : IExceptionFilter /// /// Initializes a new instance of the class. /// - /// Service de journalisation injecté. + /// Service de journalisation injecte. public GlobalExceptionFilter(ILogger logger) { this.logger = logger; @@ -22,11 +22,14 @@ public class GlobalExceptionFilter : IExceptionFilter /// public void OnException(ExceptionContext context) { + string detail = BuildExceptionDetail(context.Exception); + this.logger.LogError( context.Exception, - "Erreur non gérée dans {Action} : {Message}", + "Erreur non geree dans {Action} : {Message} | Details: {Details}", context.ActionDescriptor.DisplayName, - context.Exception.Message); + context.Exception.Message, + detail); context.Result = new ObjectResult(new { @@ -39,4 +42,18 @@ public class GlobalExceptionFilter : IExceptionFilter context.ExceptionHandled = true; } + + private static string BuildExceptionDetail(Exception exception) + { + var messages = new List(); + Exception? current = exception; + + while (current != null) + { + messages.Add($"{current.GetType().Name}: {current.Message}"); + current = current.InnerException; + } + + return string.Join(" --> ", messages); + } } \ No newline at end of file From 22940c814553a2f9c3e9aa99bf6ca69d49a73ca7 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 20:50:37 +0200 Subject: [PATCH 4/7] #199 : Nouveau test. --- Webzine.WebApplication/Controllers/TitreController.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs index e4e8d67..9aefe66 100644 --- a/Webzine.WebApplication/Controllers/TitreController.cs +++ b/Webzine.WebApplication/Controllers/TitreController.cs @@ -123,15 +123,11 @@ namespace Webzine.WebApplication.Controllers if (titreToUpdate != null) { - var utcNow = DateTime.UtcNow; - var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Europe/Paris"); - var localTime = TimeZoneInfo.ConvertTimeFromUtc(utcNow, timeZone); - var commentaire = new Commentaire { Auteur = model.Auteur, Contenu = model.Contenu, - DateCreation = localTime, + DateCreation = DateTime.UtcNow, IdTitre = model.IdTitre, }; From c43a7047774ddbbe89f51635ace3b4a093763ae3 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 21:17:40 +0200 Subject: [PATCH 5/7] =?UTF-8?q?#199=20:=20Styles=20manquants=20sur=20les?= =?UTF-8?q?=20titres=20en=20page=20d'accueil=20et=20modification=20du=20d?= =?UTF-8?q?=C3=A9ploiement.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy-prod.yaml | 2 +- Webzine.Repository/DbTitreRepository.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/deploy-prod.yaml b/.gitea/workflows/deploy-prod.yaml index 0bb9c60..b2a359a 100644 --- a/.gitea/workflows/deploy-prod.yaml +++ b/.gitea/workflows/deploy-prod.yaml @@ -3,7 +3,7 @@ name: Deploiement API Prod Docker on: push: branches: - - dev + - main jobs: deploy: diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs index a581fe9..ae14698 100644 --- a/Webzine.Repository/DbTitreRepository.cs +++ b/Webzine.Repository/DbTitreRepository.cs @@ -421,7 +421,8 @@ public class DbTitreRepository : ITitreRepository .AsNoTracking() .OrderByDescending(t => t.DateCreation) .Paginate(offset, limit) - .Include(t => t.Artiste); + .Include(t => t.Artiste) + .Include(a => a.Styles); } catch (Exception ex) { From d83791b793a8253b3f5a56e7358974b9bda0df88 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 21:37:44 +0200 Subject: [PATCH 6/7] =?UTF-8?q?#199=20:=20Test=20pour=20donn=C3=A9es=20spo?= =?UTF-8?q?tify.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 +- Webzine.WebApplication/appsettings.Production.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd375cc..a079f24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN dotnet publish "./Webzine.WebApplication.csproj" -c $BUILD_CONFIGURATION -o FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Webzine.WebApplication.dll"] +ENTRYPOINT ["dotnet", "Webzine.WebApplication.dll --seed"] diff --git a/Webzine.WebApplication/appsettings.Production.json b/Webzine.WebApplication/appsettings.Production.json index cc00e7d..fc0df2b 100644 --- a/Webzine.WebApplication/appsettings.Production.json +++ b/Webzine.WebApplication/appsettings.Production.json @@ -1,8 +1,8 @@ { - "Seeder": "Local", + "Seeder": "Spotify", "Repository": "Db", "SpotifySeeder": { - "ClientId": "", - "ClientSecret": "" + "ClientId": "390689c2fc79408b830d2f518375ef84", + "ClientSecret": "6e98a09c77ad43ae93bc0f0560cfcbe1" } } From 2d9a7a922f67499c7d38c48bec165526ef4002b4 Mon Sep 17 00:00:00 2001 From: Loic Masi Date: Wed, 8 Apr 2026 21:44:45 +0200 Subject: [PATCH 7/7] #199 : Modification du dockerfile. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index a079f24..d242018 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN dotnet publish "./Webzine.WebApplication.csproj" -c $BUILD_CONFIGURATION -o FROM base AS final WORKDIR /app COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "Webzine.WebApplication.dll --seed"] +ENTRYPOINT ["dotnet", "Webzine.WebApplication.dll", "--seed"]