transfer from private server/git server
This commit is contained in:
55
web/routes/dashboard.py
Normal file
55
web/routes/dashboard.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""routes/dashboard.py — page d'accueil + API des widgets (layout)."""
|
||||
|
||||
from flask import Blueprint, current_app, jsonify, redirect, render_template, request, url_for
|
||||
|
||||
from services import block_service
|
||||
from services.auth_service import current_user, is_admin, is_authenticated, require_admin
|
||||
|
||||
bp = Blueprint("dashboard", __name__)
|
||||
|
||||
|
||||
def _db():
|
||||
return current_app.config["DB"]
|
||||
|
||||
|
||||
@bp.route("/")
|
||||
def index():
|
||||
if not is_authenticated():
|
||||
return redirect(url_for("auth.login"))
|
||||
return render_template("view/index.html", user=current_user())
|
||||
|
||||
|
||||
@bp.route("/api/is_admin")
|
||||
def api_is_admin():
|
||||
return jsonify({"admin": is_admin()})
|
||||
|
||||
|
||||
@bp.route("/api/layout", methods=["GET"])
|
||||
def get_layout():
|
||||
return jsonify(block_service.list_blocks(_db()))
|
||||
|
||||
|
||||
@bp.route("/api/layout/save", methods=["POST"])
|
||||
@require_admin
|
||||
def save_layout():
|
||||
block_service.save_layout(_db(), request.json or [])
|
||||
return jsonify({"status": "saved"})
|
||||
|
||||
|
||||
@bp.route("/api/block/add", methods=["POST"])
|
||||
@require_admin
|
||||
def add_block():
|
||||
data = request.json or {}
|
||||
block = block_service.add_block(
|
||||
_db(), data.get("type"), data.get("column", "center"), data.get("data", {})
|
||||
)
|
||||
return jsonify(block)
|
||||
|
||||
|
||||
@bp.route("/api/block/<int:block_id>", methods=["DELETE"])
|
||||
@require_admin
|
||||
def delete_block(block_id):
|
||||
rows = block_service.delete_block(_db(), block_id)
|
||||
if rows:
|
||||
return jsonify({"status": "deleted"})
|
||||
return jsonify({"error": "not found"}), 404
|
||||
Reference in New Issue
Block a user