mirror of
https://github.com/skoelle/focusapp.git
synced 2026-09-17 20:10:25 +00:00
cleanup 2
This commit is contained in:
@@ -40,4 +40,3 @@ temp/
|
||||
README.md
|
||||
LICENSE
|
||||
init-db.sql
|
||||
init-db.sh
|
||||
|
||||
+1
-4
@@ -3,7 +3,4 @@ DB_HOST=maria-db-server.domain.local
|
||||
DB_PORT=3306
|
||||
DB_NAME=focusapp
|
||||
DB_USER=focusapp
|
||||
DB_PASSWORD=change-password
|
||||
|
||||
# MariaDB Root (fuer init-db.sh)
|
||||
DB_ROOT_PASSWORD=change-root-password
|
||||
DB_PASSWORD=<CHANGE_ME>
|
||||
|
||||
@@ -128,27 +128,3 @@ public class FocusTasksController : ControllerBase
|
||||
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; }
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="8.0.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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
@@ -4,11 +4,23 @@ using Microsoft.Extensions.FileProviders;
|
||||
|
||||
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
|
||||
builder.Services.AddDbContext<FocusContext>(options =>
|
||||
options.UseMySql(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("DefaultConnection"))
|
||||
connectionString,
|
||||
ServerVersion.AutoDetect(connectionString)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -30,11 +42,32 @@ builder.WebHost.UseUrls("http://0.0.0.0:5000");
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Ensure database is created
|
||||
// Ensure database is created (mit Retry fuer gestartete MariaDB)
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
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())
|
||||
@@ -73,7 +106,7 @@ else
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
// FALLBACK für SPA (alle nicht-API Routes >> index.html)
|
||||
// FALLBACK f�r SPA (alle nicht-API Routes >> index.html)
|
||||
app.MapFallback(async context =>
|
||||
{
|
||||
var indexPath = Path.Combine(clientPath, "index.html");
|
||||
|
||||
@@ -26,9 +26,8 @@ Die FocusApp benötigt eine MariaDB Datenbank. Das Init-Script erstellt die Date
|
||||
# .env editieren - echte MariaDB-Zugangsdaten eintragen
|
||||
vim .env
|
||||
|
||||
# Init-Script ausfuehren (benoetigt MariaDB Root-Zugang)
|
||||
chmod +x init-db.sh
|
||||
./init-db.sh
|
||||
# Init-Script als MariaDB Root ausfuehren
|
||||
mysql -h $DB_HOST -u root -p < init-db.sql
|
||||
```
|
||||
|
||||
Die `.env` enthalt:
|
||||
@@ -180,15 +179,15 @@ FocusApp/
|
||||
├── Data/
|
||||
│ └── FocusContext.cs # EF Core DbContext
|
||||
├── Models/
|
||||
│ └── FocusTask.cs # Domain Model
|
||||
│ ├── FocusTask.cs # Domain Model
|
||||
│ └── Dtos.cs # API Data Transfer Objects
|
||||
├── Program.cs # ASP.NET Startup
|
||||
├── FocusApp.csproj # Projekt-Datei
|
||||
├── appsettings.json # Config
|
||||
├── Dockerfile # Multi-Stage Docker Build
|
||||
├── docker-compose.yml # Docker Compose Konfiguration
|
||||
├── .env.example # Environment Template
|
||||
├── init-db.sql # MariaDB Init Script
|
||||
└── init-db.sh # DB Init Shell Script
|
||||
└── init-db.sql # MariaDB Init Script
|
||||
```
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
@@ -210,7 +209,7 @@ docker compose ps
|
||||
mysql -h $DB_HOST -u $DB_USER -p
|
||||
|
||||
# DB neu initialisieren
|
||||
./init-db.sh
|
||||
mysql -h $DB_HOST -u root -p < init-db.sql
|
||||
```
|
||||
|
||||
### Port bereits belegt
|
||||
|
||||
-41
@@ -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!"
|
||||
Reference in New Issue
Block a user