diff --git a/__pycache__/app.cpython-313.pyc b/__pycache__/app.cpython-313.pyc index 2cb22aa..035c71e 100644 Binary files a/__pycache__/app.cpython-313.pyc and b/__pycache__/app.cpython-313.pyc differ diff --git a/app.py b/app.py index 2b712f8..18bf024 100644 --- a/app.py +++ b/app.py @@ -733,7 +733,94 @@ def delete_mindmap(mindmap_id): flash('Mindmap erfolgreich gelöscht!', 'success') return redirect(url_for('profile')) -# API-Endpunkte für Mindmap-Daten +# API-Endpunkte für UserMindmap CRUD-Operationen +@app.route('/api/mindmaps', methods=['POST']) +@login_required +def api_create_user_mindmap(): + data = request.get_json() + name = data.get('name') + description = data.get('description') + is_private = data.get('is_private', True) + + if not name: + return jsonify({'error': 'Name ist erforderlich'}), 400 + + new_mindmap = UserMindmap( + name=name, + description=description, + user_id=current_user.id, + is_private=is_private + ) + db.session.add(new_mindmap) + db.session.commit() + return jsonify({ + 'id': new_mindmap.id, + 'name': new_mindmap.name, + 'description': new_mindmap.description, + 'is_private': new_mindmap.is_private, + 'user_id': new_mindmap.user_id, + 'created_at': new_mindmap.created_at.isoformat(), + 'last_modified': new_mindmap.last_modified.isoformat() + }), 201 + +@app.route('/api/mindmaps', methods=['GET']) +@login_required +def api_get_user_mindmaps(): + mindmaps = UserMindmap.query.filter_by(user_id=current_user.id).all() + return jsonify([{ + 'id': m.id, + 'name': m.name, + 'description': m.description, + 'is_private': m.is_private, + 'created_at': m.created_at.isoformat(), + 'last_modified': m.last_modified.isoformat() + } for m in mindmaps]) + +@app.route('/api/mindmaps/', methods=['GET']) +@login_required +def api_get_user_mindmap_detail(mindmap_id): + mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404() + # Bestehende Logik von get_user_mindmap kann hier wiederverwendet oder angepasst werden + # Für eine einfache Detailansicht: + return jsonify({ + 'id': mindmap.id, + 'name': mindmap.name, + 'description': mindmap.description, + 'is_private': mindmap.is_private, + 'user_id': mindmap.user_id, + 'created_at': mindmap.created_at.isoformat(), + 'last_modified': mindmap.last_modified.isoformat(), + # Hier könnten auch Knoten und Notizen hinzugefügt werden, ähnlich wie in get_user_mindmap + }) + +@app.route('/api/mindmaps/', methods=['PUT']) +@login_required +def api_update_user_mindmap(mindmap_id): + mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404() + data = request.get_json() + + mindmap.name = data.get('name', mindmap.name) + mindmap.description = data.get('description', mindmap.description) + mindmap.is_private = data.get('is_private', mindmap.is_private) + + db.session.commit() + return jsonify({ + 'id': mindmap.id, + 'name': mindmap.name, + 'description': mindmap.description, + 'is_private': mindmap.is_private, + 'last_modified': mindmap.last_modified.isoformat() + }) + +@app.route('/api/mindmaps/', methods=['DELETE']) +@login_required +def api_delete_user_mindmap(mindmap_id): + mindmap = UserMindmap.query.filter_by(id=mindmap_id, user_id=current_user.id).first_or_404() + db.session.delete(mindmap) + db.session.commit() + return jsonify({'message': 'Mindmap erfolgreich gelöscht'}), 200 + +# API-Endpunkte für Mindmap-Daten (öffentlich und benutzerspezifisch) @app.route('/api/mindmap/public') def get_public_mindmap(): """Liefert die Standard-Mindmap-Struktur basierend auf Kategorien.""" diff --git a/templates/my_account.html b/templates/my_account.html index 3359758..fce6524 100644 --- a/templates/my_account.html +++ b/templates/my_account.html @@ -84,6 +84,23 @@ + + +
+
+

+ + Meine erstellten Mindmaps +

+ +
+
+ +

Lade Mindmaps...

+
+
@@ -123,6 +140,424 @@
+ + + + + +