feat(templates): add category-based organization
- Added 'category' column to routine_templates table - Categorized all 12 templates into: Daily Routines, Getting Things Done, Health & Body, Errands - Added /api/templates/categories endpoint to list unique categories - Updated /api/templates to support filtering by category query param - Redesigned templates page with collapsible accordion sections by category - Categories are sorted in logical order (Daily → Work → Health → Errands) - All categories expanded by default for easy browsing
This commit is contained in:
@@ -33,16 +33,39 @@ def register(app):
|
||||
|
||||
@app.route("/api/templates", methods=["GET"])
|
||||
def api_listTemplates():
|
||||
"""List all available templates."""
|
||||
"""List all available templates. Optional query param: category"""
|
||||
user_uuid = _auth(flask.request)
|
||||
if not user_uuid:
|
||||
return flask.jsonify({"error": "unauthorized"}), 401
|
||||
templates = postgres.select("routine_templates", order_by="name")
|
||||
|
||||
# Check for category filter
|
||||
category = flask.request.args.get('category')
|
||||
if category:
|
||||
templates = postgres.select("routine_templates", where={"category": category}, order_by="name")
|
||||
else:
|
||||
templates = postgres.select("routine_templates", order_by="category, name")
|
||||
|
||||
for template in templates:
|
||||
steps = postgres.select("routine_template_steps", {"template_id": template["id"]}, order_by="position")
|
||||
template["step_count"] = len(steps)
|
||||
return flask.jsonify(templates), 200
|
||||
|
||||
@app.route("/api/templates/categories", methods=["GET"])
|
||||
def api_listTemplateCategories():
|
||||
"""List all unique template categories."""
|
||||
user_uuid = _auth(flask.request)
|
||||
if not user_uuid:
|
||||
return flask.jsonify({"error": "unauthorized"}), 401
|
||||
|
||||
# Get distinct categories
|
||||
result = postgres.execute("""
|
||||
SELECT DISTINCT category FROM routine_templates
|
||||
WHERE category IS NOT NULL
|
||||
ORDER BY category
|
||||
""")
|
||||
categories = [row["category"] for row in result]
|
||||
return flask.jsonify(categories), 200
|
||||
|
||||
@app.route("/api/templates", methods=["POST"])
|
||||
def api_createTemplate():
|
||||
"""Create a new template (admin only in production). Body: {name, description?, icon?}"""
|
||||
|
||||
Reference in New Issue
Block a user