feat: 6.0 - Backend API - GET /api/habits with streaks
This commit is contained in:
@@ -789,7 +789,7 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
||||
self.send_json({'error': str(e)}, 500)
|
||||
|
||||
def handle_habits_get(self):
|
||||
"""Get all habits from habits.json."""
|
||||
"""Get all habits from habits.json with calculated streaks."""
|
||||
try:
|
||||
habits_file = KANBAN_DIR / 'habits.json'
|
||||
|
||||
@@ -816,8 +816,26 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
|
||||
habits = data.get('habits', [])
|
||||
last_updated = data.get('lastUpdated', datetime.now().isoformat())
|
||||
|
||||
# Get today's date in YYYY-MM-DD format
|
||||
today = datetime.now().date().isoformat()
|
||||
|
||||
# Enhance each habit with streak and checkedToday
|
||||
enhanced_habits = []
|
||||
for habit in habits:
|
||||
# Calculate streak using the utility function
|
||||
completions = habit.get('completions', [])
|
||||
frequency = habit.get('frequency', 'daily')
|
||||
streak = calculate_streak(completions, frequency)
|
||||
|
||||
# Check if habit was completed today
|
||||
checked_today = today in completions
|
||||
|
||||
# Add calculated fields to habit
|
||||
enhanced_habit = {**habit, 'streak': streak, 'checkedToday': checked_today}
|
||||
enhanced_habits.append(enhanced_habit)
|
||||
|
||||
self.send_json({
|
||||
'habits': habits,
|
||||
'habits': enhanced_habits,
|
||||
'lastUpdated': last_updated
|
||||
})
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user