cleanup 2

This commit is contained in:
2026-08-09 14:05:44 +02:00
parent 7e0c60253e
commit 44a52f1164
8 changed files with 70 additions and 83 deletions
-1
View File
@@ -40,4 +40,3 @@ temp/
README.md README.md
LICENSE LICENSE
init-db.sql init-db.sql
init-db.sh
+1 -4
View File
@@ -3,7 +3,4 @@ DB_HOST=maria-db-server.domain.local
DB_PORT=3306 DB_PORT=3306
DB_NAME=focusapp DB_NAME=focusapp
DB_USER=focusapp DB_USER=focusapp
DB_PASSWORD=change-password DB_PASSWORD=<CHANGE_ME>
# MariaDB Root (fuer init-db.sh)
DB_ROOT_PASSWORD=change-root-password
-24
View File
@@ -128,27 +128,3 @@ public class FocusTasksController : ControllerBase
return NoContent(); return NoContent();
} }
} }
public class CreateTaskDto
{
public string Title { get; set; } = string.Empty;
public string? Description { get; set; }
}
public class UpdateTaskDto
{
public string? Title { get; set; }
public string? Description { get; set; }
public int? Order { get; set; }
}
public class ReorderDto
{
public List<OrderItem> Orders { get; set; } = new();
}
public class OrderItem
{
public int Id { get; set; }
public int Order { get; set; }
}
-1
View File
@@ -14,7 +14,6 @@
</PackageReference> </PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="System.Text.Json" Version="8.0.6" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+25
View File
@@ -0,0 +1,25 @@
namespace FocusApp.Models;
public class CreateTaskDto
{
public string Title { get; set; } = string.Empty;
public string? Description { get; set; }
}
public class UpdateTaskDto
{
public string? Title { get; set; }
public string? Description { get; set; }
public int? Order { get; set; }
}
public class ReorderDto
{
public List<OrderItem> Orders { get; set; } = new();
}
public class OrderItem
{
public int Id { get; set; }
public int Order { get; set; }
}
+38 -5
View File
@@ -4,11 +4,23 @@ using Microsoft.Extensions.FileProviders;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Connection-String aus ENV-Variablen aufbauen (appsettings.json ist Fallback)
static string BuildConnectionString(IConfiguration config)
{
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 connectionString = BuildConnectionString(builder.Configuration);
// Add services // Add services
builder.Services.AddDbContext<FocusContext>(options => builder.Services.AddDbContext<FocusContext>(options =>
options.UseMySql( options.UseMySql(
builder.Configuration.GetConnectionString("DefaultConnection"), connectionString,
ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("DefaultConnection")) ServerVersion.AutoDetect(connectionString)
) )
); );
@@ -30,11 +42,32 @@ builder.WebHost.UseUrls("http://0.0.0.0:5000");
var app = builder.Build(); var app = builder.Build();
// Ensure database is created // Ensure database is created (mit Retry fuer gestartete MariaDB)
using (var scope = app.Services.CreateScope()) using (var scope = app.Services.CreateScope())
{ {
var db = scope.ServiceProvider.GetRequiredService<FocusContext>(); var db = scope.ServiceProvider.GetRequiredService<FocusContext>();
db.Database.EnsureCreated(); var maxRetries = 5;
for (int i = 1; i <= maxRetries; i++)
{
try
{
db.Database.EnsureCreated();
Console.WriteLine("Database connected!");
break;
}
catch (Exception ex)
{
Console.WriteLine($"Database connection attempt {i}/{maxRetries} failed: {ex.Message}");
if (i == maxRetries)
{
Console.WriteLine("Could not connect to database after max retries. Exiting.");
throw;
}
var delay = Math.Min(i * 5, 30);
Console.WriteLine($"Retrying in {delay}s...");
Thread.Sleep(delay * 1000);
}
}
} }
if (app.Environment.IsDevelopment()) if (app.Environment.IsDevelopment())
@@ -73,7 +106,7 @@ else
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();
// FALLBACK für SPA (alle nicht-API Routes >> index.html) // FALLBACK fr SPA (alle nicht-API Routes >> index.html)
app.MapFallback(async context => app.MapFallback(async context =>
{ {
var indexPath = Path.Combine(clientPath, "index.html"); var indexPath = Path.Combine(clientPath, "index.html");
+6 -7
View File
@@ -26,9 +26,8 @@ Die FocusApp benötigt eine MariaDB Datenbank. Das Init-Script erstellt die Date
# .env editieren - echte MariaDB-Zugangsdaten eintragen # .env editieren - echte MariaDB-Zugangsdaten eintragen
vim .env vim .env
# Init-Script ausfuehren (benoetigt MariaDB Root-Zugang) # Init-Script als MariaDB Root ausfuehren
chmod +x init-db.sh mysql -h $DB_HOST -u root -p < init-db.sql
./init-db.sh
``` ```
Die `.env` enthalt: Die `.env` enthalt:
@@ -180,15 +179,15 @@ FocusApp/
├── Data/ ├── Data/
│ └── FocusContext.cs # EF Core DbContext │ └── FocusContext.cs # EF Core DbContext
├── Models/ ├── Models/
── FocusTask.cs # Domain Model ── FocusTask.cs # Domain Model
│ └── Dtos.cs # API Data Transfer Objects
├── Program.cs # ASP.NET Startup ├── Program.cs # ASP.NET Startup
├── FocusApp.csproj # Projekt-Datei ├── FocusApp.csproj # Projekt-Datei
├── appsettings.json # Config ├── appsettings.json # Config
├── Dockerfile # Multi-Stage Docker Build ├── Dockerfile # Multi-Stage Docker Build
├── docker-compose.yml # Docker Compose Konfiguration ├── docker-compose.yml # Docker Compose Konfiguration
├── .env.example # Environment Template ├── .env.example # Environment Template
── init-db.sql # MariaDB Init Script ── init-db.sql # MariaDB Init Script
└── init-db.sh # DB Init Shell Script
``` ```
## 🐛 Troubleshooting ## 🐛 Troubleshooting
@@ -210,7 +209,7 @@ docker compose ps
mysql -h $DB_HOST -u $DB_USER -p mysql -h $DB_HOST -u $DB_USER -p
# DB neu initialisieren # DB neu initialisieren
./init-db.sh mysql -h $DB_HOST -u root -p < init-db.sql
``` ```
### Port bereits belegt ### Port bereits belegt
-41
View File
@@ -1,41 +0,0 @@
#!/bin/bash
# FocusApp Datenbank Initialisierung
# Fuehrt init-db.sql gegen den externen MariaDB Server aus
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# .env laden
if [ -f "$SCRIPT_DIR/.env" ]; then
export $(grep -v '^#' "$SCRIPT_DIR/.env" | xargs)
else
echo "Fehler: .env Datei nicht gefunden unter $SCRIPT_DIR/.env"
exit 1
fi
# Pruefen ob notwendige Variablen gesetzt sind
if [ -z "$DB_HOST" ] || [ -z "$DB_ROOT_PASSWORD" ]; then
echo "Fehler: DB_HOST und DB_ROOT_PASSWORD muessen in .env gesetzt sein"
exit 1
fi
DB_PORT=${DB_PORT:-3306}
echo "Verbinde zu MariaDB auf $DB_HOST:$DB_PORT..."
# Pruefen ob mysql/mariadb Client verfuegbar ist
if command -v mariadb &> /dev/null; then
MYSQL_CMD="mariadb"
elif command -v mysql &> /dev/null; then
MYSQL_CMD="mysql"
else
echo "Fehler: weder 'mariadb' noch 'mysql' Client gefunden"
echo "Installieren Sie: sudo apt install mariadb-client"
exit 1
fi
# SQL ausfuehren
$MYSQL_CMD -h "$DB_HOST" -P "$DB_PORT" -u root -p"$DB_ROOT_PASSWORD" < "$SCRIPT_DIR/init-db.sql"
echo "Datenbank focusapp erfolgreich initialisiert!"