From 63e755c5c79524077cb146568962b6260dd48b3f Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 10:07:47 +0200 Subject: [PATCH 1/4] =?UTF-8?q?refactor:=20#150=20mettre=20=C3=A0=20jour?= =?UTF-8?q?=20appsettings=20et=20introduire=20des=20enums=20pour=20les=20t?= =?UTF-8?q?ypes=20Seeder=20et=20Repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/pr-endpoint-check.yml | 16 ++----- .../Dockerfile => Dockerfile | 2 +- .../Configuration/AppEnums.cs | 13 ++++++ Webzine.WebApplication/Program.cs | 42 +++++++------------ .../appsettings.Development.json | 8 +--- .../appsettings.Production.json | 4 ++ Webzine.WebApplication/appsettings.json | 6 +-- 7 files changed, 39 insertions(+), 52 deletions(-) rename Webzine.WebApplication/Dockerfile => Dockerfile (88%) create mode 100644 Webzine.WebApplication/Configuration/AppEnums.cs create mode 100644 Webzine.WebApplication/appsettings.Production.json diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index 427f687..aadf030 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -11,20 +11,10 @@ jobs: - name: Checkout PR branch uses: actions/checkout@v4 - - name: Configure appsettings for CI + - name: Configure environment for CI run: | - # Find the appsettings.json file - APPSETTINGS_PATH="Webzine.WebApplication/appsettings.json" - - # Backup original file - cp $APPSETTINGS_PATH $APPSETTINGS_PATH.bak - - # Use jq to modify the JSON - jq '.UseDatabase = true | .IsSQLite = true' $APPSETTINGS_PATH > $APPSETTINGS_PATH.tmp - mv $APPSETTINGS_PATH.tmp $APPSETTINGS_PATH - - echo "Updated appsettings.json:" - cat $APPSETTINGS_PATH + echo "ASPNETCORE_ENVIRONMENT=Development" >> $ACT_ENV + echo "Repository=Db" >> $ACT_ENV - name: Setup .NET 10 uses: actions/setup-dotnet@v4 diff --git a/Webzine.WebApplication/Dockerfile b/Dockerfile similarity index 88% rename from Webzine.WebApplication/Dockerfile rename to Dockerfile index 3211249..bd375cc 100644 --- a/Webzine.WebApplication/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ EXPOSE 8081 FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src -COPY ["Webzine.WebApplication/Webzine.WebApplication.csproj", "Webzine.WebApplication/"] +COPY ["./Webzine.WebApplication/Webzine.WebApplication.csproj", "Webzine.WebApplication/"] RUN dotnet restore "Webzine.WebApplication/Webzine.WebApplication.csproj" COPY . . WORKDIR "/src/Webzine.WebApplication" diff --git a/Webzine.WebApplication/Configuration/AppEnums.cs b/Webzine.WebApplication/Configuration/AppEnums.cs new file mode 100644 index 0000000..93d4e8b --- /dev/null +++ b/Webzine.WebApplication/Configuration/AppEnums.cs @@ -0,0 +1,13 @@ +namespace Webzine.WebApplication.Configuration; + +public enum SeederType +{ + Local, + Spotify +} + +public enum RepositoryType +{ + Local, + Db +} \ No newline at end of file diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index ae26f07..1b763dc 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -8,6 +8,7 @@ using Webzine.Entity; using Webzine.Entity.Fixtures; using Webzine.Repository; using Webzine.Repository.Contracts; +using Webzine.WebApplication.Configuration; using Webzine.WebApplication.Extensions; // Initiation du logger NLog pour la classe courante afin de pouvoir l'utiliser pour logger des messages d'information, d'erreur, etc avant la construction de l'application. @@ -32,19 +33,19 @@ try builder.Host.UseNLog(); // En fonction de la configuration, utilise soit les repositories basés sur une base de données, soit les repositories basés sur des listes locales. - bool useDatabase = builder.Configuration.GetValue("UseDatabase"); - bool isSQLite = builder.Configuration.GetValue("IsSQLite"); - if (useDatabase) + var repositoryType = builder.Configuration.GetValue("Repository"); + var seederType = builder.Configuration.GetValue("Seeder"); + if (repositoryType == RepositoryType.Db) { - if (isSQLite) + if (builder.Environment.IsProduction()) { builder.Services.AddDbContext(options => - options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection"))); + options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection"))); } else { builder.Services.AddDbContext(options => - options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection"))); + options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection"))); } builder.Services.AddScoped(); @@ -68,30 +69,15 @@ try var app = builder.Build(); - if (useDatabase) + if (repositoryType == RepositoryType.Db) { - if (isSQLite) + using (var scope = app.Services.CreateScope()) { - using (var scope = app.Services.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureDeleted(); - db.Database.EnsureCreated(); - var repo = scope.ServiceProvider.GetRequiredService(); - repo.SeedBaseDeDonnees(); - } - } - else - { - using (var scope = app.Services.CreateScope()) - { - // TODO : A modifier pour ne pas supprimer la base de donnée en prod - var db = scope.ServiceProvider.GetRequiredService(); - db.Database.EnsureDeleted(); - db.Database.EnsureCreated(); - var repo = scope.ServiceProvider.GetRequiredService(); - repo.SeedBaseDeDonnees(); - } + var db = scope.ServiceProvider.GetRequiredService(); + db.Database.EnsureDeleted(); + db.Database.EnsureCreated(); + var repo = scope.ServiceProvider.GetRequiredService(); + repo.SeedBaseDeDonnees(); } } else diff --git a/Webzine.WebApplication/appsettings.Development.json b/Webzine.WebApplication/appsettings.Development.json index 0c208ae..79222b7 100644 --- a/Webzine.WebApplication/appsettings.Development.json +++ b/Webzine.WebApplication/appsettings.Development.json @@ -1,8 +1,4 @@ { - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } + "Seeder": "Local", + "Repository": "Db" } diff --git a/Webzine.WebApplication/appsettings.Production.json b/Webzine.WebApplication/appsettings.Production.json new file mode 100644 index 0000000..0609b7f --- /dev/null +++ b/Webzine.WebApplication/appsettings.Production.json @@ -0,0 +1,4 @@ +{ + "Seeder": "Local", + "Repository": "Db" +} \ No newline at end of file diff --git a/Webzine.WebApplication/appsettings.json b/Webzine.WebApplication/appsettings.json index fc87614..ac0f745 100644 --- a/Webzine.WebApplication/appsettings.json +++ b/Webzine.WebApplication/appsettings.json @@ -9,11 +9,9 @@ "NombreDerniereChronique": 3, "NombreDeTopTitres": 3 }, - "UseDatabase": true, - "IsSQLite": true, "ConnectionStrings": { "SqliteConnection": "Data Source=Data/webzine.sqlite", - "PostGreSQLConnection" : "Host=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db" + "PostGreSQLConnection": "Host=192.168.60.50;Port=5432;Username=postgres;Password=BcS4e6DHr2NgVrnPomVI;Database=webzine_prod" }, "AllowedHosts": "*" -} +} \ No newline at end of file From 29f1fd97be59f1e2807cba211d337694bc095c1d Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 10:08:08 +0200 Subject: [PATCH 2/4] =?UTF-8?q?refactor:=20mise=20=C3=A0=20jour=20la=20ver?= =?UTF-8?q?sion=20de=20l'application=20=C3=A0=203.0=20dans=20ApiController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.WebApplication/Controllers/ApiController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Webzine.WebApplication/Controllers/ApiController.cs b/Webzine.WebApplication/Controllers/ApiController.cs index 1b1beca..f01d7a1 100644 --- a/Webzine.WebApplication/Controllers/ApiController.cs +++ b/Webzine.WebApplication/Controllers/ApiController.cs @@ -29,7 +29,7 @@ public class ApiController : ControllerBase return this.Ok(new { nom = "webzine", - version = "2.0", + version = "3.0", }); } } \ No newline at end of file From aa4ad9ef8e4618eef86a040c4da66a592eac0995 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 10:22:11 +0200 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20mise=20=C3=A0=20jour=20la=20con?= =?UTF-8?q?figuration=20des=20variables=20d=E2=80=99environnement=20dans?= =?UTF-8?q?=20pr-endpoint-check.yml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/pr-endpoint-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/pr-endpoint-check.yml b/.gitea/workflows/pr-endpoint-check.yml index aadf030..e487e80 100644 --- a/.gitea/workflows/pr-endpoint-check.yml +++ b/.gitea/workflows/pr-endpoint-check.yml @@ -13,8 +13,8 @@ jobs: - name: Configure environment for CI run: | - echo "ASPNETCORE_ENVIRONMENT=Development" >> $ACT_ENV - echo "Repository=Db" >> $ACT_ENV + echo "ASPNETCORE_ENVIRONMENT=Development" >> "${GITHUB_ENV:-$ACT_ENV}" + echo "Repository=Db" >> "${GITHUB_ENV:-$ACT_ENV}" - name: Setup .NET 10 uses: actions/setup-dotnet@v4 From fa778a8711dd2c017ac9374bb30505d73291a471 Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Tue, 31 Mar 2026 14:42:43 +0200 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20mettre=20=C3=A0=20jour=20la=20c?= =?UTF-8?q?ha=C3=AEne=20de=20connexion=20PostgreSQL=20dans=20appsettings.j?= =?UTF-8?q?son?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.WebApplication/appsettings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Webzine.WebApplication/appsettings.json b/Webzine.WebApplication/appsettings.json index ac0f745..20bd894 100644 --- a/Webzine.WebApplication/appsettings.json +++ b/Webzine.WebApplication/appsettings.json @@ -11,7 +11,7 @@ }, "ConnectionStrings": { "SqliteConnection": "Data Source=Data/webzine.sqlite", - "PostGreSQLConnection": "Host=192.168.60.50;Port=5432;Username=postgres;Password=BcS4e6DHr2NgVrnPomVI;Database=webzine_prod" + "PostGreSQLConnection": "Host=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db" }, "AllowedHosts": "*" } \ No newline at end of file