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/Controllers/ApiController.cs b/Webzine.WebApplication/Controllers/ApiController.cs index 42f72bb..0327185 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 diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 2a19bd7..42354ea 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -11,6 +11,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. @@ -35,19 +36,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(); @@ -71,30 +72,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..20bd894 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=localhost;Port=5432;Username=admin;Password=admin123;Database=webzine_db" }, "AllowedHosts": "*" -} +} \ No newline at end of file