Goals -System refactored - Platzhaltersystem enhanced (als draft) #53

Merged
Lars merged 86 commits from develop into main 2026-03-31 11:46:48 +02:00
Showing only changes of commit 97defaf704 - Show all commits

View File

@ -25,6 +25,19 @@ from goal_utils import get_current_value_for_goal
router = APIRouter(prefix="/api/goals", tags=["goals"]) router = APIRouter(prefix="/api/goals", tags=["goals"])
def serialize_dates(obj):
"""Convert date/datetime objects to ISO format strings for JSON serialization."""
if obj is None:
return None
if isinstance(obj, dict):
return {k: serialize_dates(v) for k, v in obj.items()}
if isinstance(obj, list):
return [serialize_dates(item) for item in obj]
if isinstance(obj, (date,)):
return obj.isoformat()
return obj
# ============================================================================ # ============================================================================
# Pydantic Models # Pydantic Models
# ============================================================================ # ============================================================================
@ -362,6 +375,9 @@ def list_goals(session: dict = Depends(require_auth)):
print(f"[ERROR] Failed to update progress for goal {goal.get('id')}: {e}") print(f"[ERROR] Failed to update progress for goal {goal.get('id')}: {e}")
# Continue with other goals even if one fails # Continue with other goals even if one fails
# Serialize date objects to ISO format strings
goals = serialize_dates(goals)
return goals return goals
except Exception as e: except Exception as e:
@ -700,6 +716,9 @@ def get_goals_grouped(session: dict = Depends(require_auth)):
goal_dict['focus_contributions'] = focus_map.get(goal['id'], []) goal_dict['focus_contributions'] = focus_map.get(goal['id'], [])
grouped[cat].append(goal_dict) grouped[cat].append(goal_dict)
# Serialize date objects to ISO format strings
grouped = serialize_dates(grouped)
return grouped return grouped
# ============================================================================ # ============================================================================