"feat: Implement new notification system in frontend

This commit is contained in:
2025-05-29 10:04:55 +02:00
parent 08c922d8f5
commit c256848d59
6 changed files with 478 additions and 19 deletions

View File

@@ -3957,6 +3957,101 @@ def export_admin_logs():
# ===== ENDE FEHLENDE ADMIN-API-ENDPUNKTE =====
# ===== BENACHRICHTIGUNGS-API-ENDPUNKTE =====
@app.route('/api/notifications', methods=['GET'])
@login_required
def get_notifications():
"""Holt alle Benachrichtigungen für den aktuellen Benutzer"""
try:
db_session = get_db_session()
# Benachrichtigungen für den aktuellen Benutzer laden
notifications = db_session.query(Notification).filter(
Notification.user_id == current_user.id
).order_by(Notification.created_at.desc()).limit(50).all()
notifications_data = [notification.to_dict() for notification in notifications]
db_session.close()
return jsonify({
"success": True,
"notifications": notifications_data
})
except Exception as e:
app_logger.error(f"Fehler beim Laden der Benachrichtigungen: {str(e)}")
return jsonify({
"success": False,
"message": f"Fehler beim Laden der Benachrichtigungen: {str(e)}"
}), 500
@app.route('/api/notifications/<int:notification_id>/read', methods=['POST'])
@login_required
def mark_notification_read(notification_id):
"""Markiert eine Benachrichtigung als gelesen"""
try:
db_session = get_db_session()
notification = db_session.query(Notification).filter(
Notification.id == notification_id,
Notification.user_id == current_user.id
).first()
if not notification:
db_session.close()
return jsonify({
"success": False,
"message": "Benachrichtigung nicht gefunden"
}), 404
notification.read = True
db_session.commit()
db_session.close()
return jsonify({
"success": True,
"message": "Benachrichtigung als gelesen markiert"
})
except Exception as e:
app_logger.error(f"Fehler beim Markieren der Benachrichtigung: {str(e)}")
return jsonify({
"success": False,
"message": f"Fehler beim Markieren: {str(e)}"
}), 500
@app.route('/api/notifications/mark-all-read', methods=['POST'])
@login_required
def mark_all_notifications_read():
"""Markiert alle Benachrichtigungen als gelesen"""
try:
db_session = get_db_session()
# Alle ungelesenen Benachrichtigungen des Benutzers finden und als gelesen markieren
updated_count = db_session.query(Notification).filter(
Notification.user_id == current_user.id,
Notification.read == False
).update({"read": True})
db_session.commit()
db_session.close()
return jsonify({
"success": True,
"message": f"{updated_count} Benachrichtigungen als gelesen markiert"
})
except Exception as e:
app_logger.error(f"Fehler beim Markieren aller Benachrichtigungen: {str(e)}")
return jsonify({
"success": False,
"message": f"Fehler beim Markieren: {str(e)}"
}), 500
# ===== ENDE BENACHRICHTIGUNGS-API-ENDPUNKTE =====
# ===== STARTUP UND MAIN =====
if __name__ == "__main__":