From af4389a7b9c4c228f7aad53b8454515626732741 Mon Sep 17 00:00:00 2001 From: Stefan Koelle Date: Sun, 9 Aug 2026 16:43:59 +0200 Subject: [PATCH] feat: demo mode with SQLite and seed tasks --- Data/FocusContext.cs | 10 ++++++++++ FocusApp.csproj | 1 + Program.cs | 46 +++++++++++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/Data/FocusContext.cs b/Data/FocusContext.cs index 3bd27fe..fa683cd 100644 --- a/Data/FocusContext.cs +++ b/Data/FocusContext.cs @@ -26,5 +26,15 @@ public class FocusContext : DbContext entity.Property(e => e.CreatedAt).IsRequired(); entity.Property(e => e.UpdatedAt).IsRequired(); }); + + // Demo-Tasks fuer lokalen Test + var now = DateTime.UtcNow; + modelBuilder.Entity().HasData( + new FocusTask { Id = 1, Title = "Projektstruktur klären", Description = "README, AGENTS.md, Lizenz", Order = 1, CreatedAt = now, UpdatedAt = now }, + new FocusTask { Id = 2, Title = "API finalisieren", Description = "Health Endpoint, Validierung", Order = 2, CreatedAt = now, UpdatedAt = now }, + new FocusTask { Id = 3, Title = "Frontend polishieren", Description = "CSS, Responsive, Tests", Order = 3, CreatedAt = now, UpdatedAt = now }, + new FocusTask { Id = 4, Title = "Docker Setup prüfen", Description = "Healthcheck, CI/CD", Order = 4, CreatedAt = now, UpdatedAt = now }, + new FocusTask { Id = 5, Title = "Doku vervollständigen", Description = "API Docs, Deployment Guide", Order = 5, CreatedAt = now, UpdatedAt = now } + ); } } diff --git a/FocusApp.csproj b/FocusApp.csproj index 166df48..de96b00 100644 --- a/FocusApp.csproj +++ b/FocusApp.csproj @@ -12,6 +12,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Program.cs b/Program.cs index 3a01f8d..f3e078f 100644 --- a/Program.cs +++ b/Program.cs @@ -8,25 +8,39 @@ var builder = WebApplication.CreateBuilder(args); builder.Logging.AddFilter("Microsoft.AspNetCore.HttpLogging", LogLevel.Information); -// Connection-String aus ENV-Variablen aufbauen (appsettings.json ist Fallback) -static string BuildConnectionString(IConfiguration config) +// Datenbank: MariaDB oder SQLite (Demo-Modus) +static void ConfigureDatabase(IConfiguration config, IServiceCollection services) { - return $"Server={config["DB_HOST"] ?? "localhost"};" + - $"Port={config["DB_PORT"] ?? "3306"};" + - $"Database={config["DB_NAME"] ?? "focusapp"};" + - $"User={config["DB_USER"] ?? "focusapp"};" + - $"Password={config["DB_PASSWORD"] ?? "change-password"}"; + var dbHost = config["DB_HOST"]; + + if (!string.IsNullOrEmpty(dbHost)) + { + // Produktion: MariaDB + var connectionString = $"Server={dbHost};" + + $"Port={config["DB_PORT"] ?? "3306"};" + + $"Database={config["DB_NAME"] ?? "focusapp"};" + + $"User={config["DB_USER"] ?? "focusapp"};" + + $"Password={config["DB_PASSWORD"] ?? "change-password"}"; + + services.AddDbContext(options => + options.UseMySql( + connectionString, + ServerVersion.AutoDetect(connectionString) + ) + ); + Console.WriteLine("Using MariaDB database"); + } + else + { + // Demo-Modus: SQLite + services.AddDbContext(options => + options.UseSqlite("Data Source=focusapp-demo.db") + ); + Console.WriteLine("Using SQLite database (demo mode)"); + } } -var connectionString = BuildConnectionString(builder.Configuration); - -// Add services -builder.Services.AddDbContext(options => - options.UseMySql( - connectionString, - ServerVersion.AutoDetect(connectionString) - ) -); +ConfigureDatabase(builder.Configuration, builder.Services); builder.Services.AddCors(options => {