diff options
author | Luca Matei Pintilie <luca@lucamatei.com> | 2024-10-30 20:59:53 +0000 |
---|---|---|
committer | Luca Matei Pintilie <luca@lucamatei.com> | 2024-10-30 20:59:53 +0000 |
commit | dc1938dbb98dc9edf16558e505b2961246c83e6e (patch) | |
tree | 7953186976085ceca6c03a208d1ffd9596f745be /Api/Program.cs | |
parent | fc3c7e3b3c955cc274d4668768466fecb8fb727b (diff) | |
download | wikiwaka-master.tar wikiwaka-master.tar.gz wikiwaka-master.tar.bz2 wikiwaka-master.tar.lz wikiwaka-master.tar.xz wikiwaka-master.tar.zst wikiwaka-master.zip |
Diffstat (limited to 'Api/Program.cs')
-rw-r--r-- | Api/Program.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Api/Program.cs b/Api/Program.cs new file mode 100644 index 0000000..0fefe46 --- /dev/null +++ b/Api/Program.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using WikiWaka.Api.Models; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddControllers(); +builder.Services.AddHealthChecks(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Services.AddDbContext<DbWikiWakaContext>(options => + options.UseSqlite(builder.Configuration.GetConnectionString("DbWikiWaka"))); + +var app = builder.Build(); + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.MapControllers(); +app.MapHealthChecks("/healthz"); + +using (var scope = app.Services.CreateScope()) +{ + await using DbWikiWakaContext db = scope.ServiceProvider.GetRequiredService<DbWikiWakaContext>(); + ILogger<Program> logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>(); + bool isNewDatabase = await db.Database.EnsureCreatedAsync(); + if (isNewDatabase) + { + logger.LogInformation("Creating new database..."); + await DbInit.InitializeLanguages(db); + } + else + logger.LogInformation("Database existed before, not changing"); +} + +app.Run(); |