feat: 2.0 - Backend API - GET /api/habits

This commit is contained in:
Echo
2026-02-10 11:09:58 +00:00
parent ee8727a8df
commit fc5ebf2026
2 changed files with 244 additions and 0 deletions

View File

@@ -251,6 +251,8 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
self.handle_cron_status()
elif self.path == '/api/activity' or self.path.startswith('/api/activity?'):
self.handle_activity()
elif self.path == '/api/habits':
self.handle_habits_get()
elif self.path.startswith('/api/files'):
self.handle_files_get()
elif self.path.startswith('/api/diff'):
@@ -681,6 +683,41 @@ class TaskBoardHandler(SimpleHTTPRequestHandler):
except Exception as e:
self.send_json({'error': str(e)}, 500)
def handle_habits_get(self):
"""Get all habits from habits.json."""
try:
habits_file = KANBAN_DIR / 'habits.json'
# Handle missing file or empty file gracefully
if not habits_file.exists():
self.send_json({
'habits': [],
'lastUpdated': datetime.now().isoformat()
})
return
# Read and parse habits data
try:
data = json.loads(habits_file.read_text(encoding='utf-8'))
except (json.JSONDecodeError, IOError):
# Return empty array on parse error instead of 500
self.send_json({
'habits': [],
'lastUpdated': datetime.now().isoformat()
})
return
# Ensure required fields exist
habits = data.get('habits', [])
last_updated = data.get('lastUpdated', datetime.now().isoformat())
self.send_json({
'habits': habits,
'lastUpdated': last_updated
})
except Exception as e:
self.send_json({'error': str(e)}, 500)
def handle_files_get(self):
"""List files or get file content."""
from urllib.parse import urlparse, parse_qs