#162 : Rebasage de la branche dev.
This commit is contained in:
@@ -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"
|
||||
@@ -268,7 +268,7 @@ public class DbTitreRepository : ITitreRepository
|
||||
.Include(t => t.Artiste)
|
||||
.Include(t => t.Styles)
|
||||
.Include(t => t.Commentaires)
|
||||
.First(t => t.IdTitre == idTitre);
|
||||
.FirstOrDefault(t => t.IdTitre == idTitre);
|
||||
|
||||
this.logger.LogDebug("Titre trouvé: {Libelle}", titre.Libelle);
|
||||
return titre;
|
||||
|
||||
13
Webzine.WebApplication/Configuration/AppEnums.cs
Normal file
13
Webzine.WebApplication/Configuration/AppEnums.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Webzine.WebApplication.Configuration;
|
||||
|
||||
public enum SeederType
|
||||
{
|
||||
Local,
|
||||
Spotify,
|
||||
}
|
||||
|
||||
public enum RepositoryType
|
||||
{
|
||||
Local,
|
||||
Db,
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class ApiController : ControllerBase
|
||||
return this.Ok(new
|
||||
{
|
||||
nom = "webzine",
|
||||
version = "2.0",
|
||||
version = "3.0",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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<bool>("UseDatabase");
|
||||
bool isSQLite = builder.Configuration.GetValue<bool>("IsSQLite");
|
||||
if (useDatabase)
|
||||
var repositoryType = builder.Configuration.GetValue<RepositoryType>("Repository");
|
||||
var seederType = builder.Configuration.GetValue<SeederType>("Seeder");
|
||||
if (repositoryType == RepositoryType.Db)
|
||||
{
|
||||
if (isSQLite)
|
||||
if (builder.Environment.IsProduction())
|
||||
{
|
||||
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection")));
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection")));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Services.AddDbContext<WebzineDbContext>(options =>
|
||||
options.UseNpgsql(builder.Configuration.GetConnectionString("PostGreSQLConnection")));
|
||||
options.UseSqlite(builder.Configuration.GetConnectionString("SqliteConnection")));
|
||||
}
|
||||
|
||||
builder.Services.AddScoped<DbEntityRepository>();
|
||||
@@ -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<WebzineDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
||||
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<WebzineDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
||||
repo.SeedBaseDeDonnees();
|
||||
}
|
||||
var db = scope.ServiceProvider.GetRequiredService<WebzineDbContext>();
|
||||
db.Database.EnsureDeleted();
|
||||
db.Database.EnsureCreated();
|
||||
var repo = scope.ServiceProvider.GetRequiredService<DbEntityRepository>();
|
||||
repo.SeedBaseDeDonnees();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
"Seeder": "Local",
|
||||
"Repository": "Db"
|
||||
}
|
||||
|
||||
4
Webzine.WebApplication/appsettings.Production.json
Normal file
4
Webzine.WebApplication/appsettings.Production.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"Seeder": "Local",
|
||||
"Repository": "Db"
|
||||
}
|
||||
@@ -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": "*"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user