91 lines
2.1 KiB
Python
Executable File
91 lines
2.1 KiB
Python
Executable File
"""Main routes."""
|
|
|
|
from flask import Blueprint, g, jsonify, redirect, render_template, url_for
|
|
|
|
from customer_portal.web.routes.auth import login_required
|
|
|
|
bp = Blueprint("main", __name__)
|
|
|
|
|
|
@bp.route("/")
|
|
def index():
|
|
"""Home page - redirect to dashboard or login."""
|
|
return redirect(url_for("auth.login"))
|
|
|
|
|
|
@bp.route("/health")
|
|
def health():
|
|
"""Health check for Docker and load balancers.
|
|
|
|
Returns:
|
|
- 200 OK if database connection works
|
|
- 503 Service Unavailable if database is down
|
|
"""
|
|
from sqlalchemy import text
|
|
|
|
from customer_portal.models import get_db
|
|
|
|
try:
|
|
db = get_db()
|
|
db.execute(text("SELECT 1"))
|
|
return (
|
|
jsonify({"status": "healthy", "database": "connected", "version": "1.0.0"}),
|
|
200,
|
|
)
|
|
except Exception as e:
|
|
return (
|
|
jsonify(
|
|
{"status": "unhealthy", "database": "disconnected", "error": str(e)}
|
|
),
|
|
503,
|
|
)
|
|
|
|
|
|
@bp.route("/api/status")
|
|
def api_status():
|
|
"""API status endpoint."""
|
|
return jsonify(
|
|
{
|
|
"status": "ok",
|
|
"message": "Kundenportal laeuft",
|
|
"version": "0.1.0",
|
|
}
|
|
)
|
|
|
|
|
|
@bp.route("/dashboard")
|
|
@login_required
|
|
def dashboard():
|
|
"""Main dashboard."""
|
|
from customer_portal.models import get_db
|
|
from customer_portal.models.booking import Booking
|
|
|
|
db = get_db()
|
|
|
|
# Get upcoming bookings (confirmed, future dates)
|
|
from datetime import date
|
|
|
|
upcoming_bookings = (
|
|
db.query(Booking)
|
|
.filter(
|
|
Booking.customer_id == g.customer.id,
|
|
Booking.status == "confirmed",
|
|
Booking.kurs_date >= date.today(),
|
|
)
|
|
.order_by(Booking.kurs_date.asc())
|
|
.limit(3)
|
|
.all()
|
|
)
|
|
|
|
# Get recent bookings count
|
|
total_bookings = (
|
|
db.query(Booking).filter(Booking.customer_id == g.customer.id).count()
|
|
)
|
|
|
|
return render_template(
|
|
"dashboard.html",
|
|
customer=g.customer,
|
|
upcoming_bookings=upcoming_bookings,
|
|
total_bookings=total_bookings,
|
|
)
|