refactor: DRY pass on backend — pagination helper and sharing utilities
- Add parse_pagination() to routes/utils.py; replace 6 duplicate limit/offset extractions in notes, tasks, chat, projects, milestones routes - Extract _enrich_shares() in sharing.py; eliminates identical 12-line loop in list_project_shares and list_note_shares - Extract _deduplicate_by_permission() in sharing.py; eliminates identical deduplication blocks in list_shared_with_me for projects and notes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import date
|
||||
|
||||
from quart import jsonify
|
||||
from quart import jsonify, request
|
||||
|
||||
|
||||
def not_found(resource: str = "Item"):
|
||||
@@ -15,3 +15,10 @@ def parse_iso_date(value: str | None, field: str = "date"):
|
||||
return date.fromisoformat(value)
|
||||
except ValueError:
|
||||
return jsonify({"error": f"Invalid {field} format. Use YYYY-MM-DD."}), 400
|
||||
|
||||
|
||||
def parse_pagination(default_limit: int = 50, max_limit: int = 500) -> tuple[int, int]:
|
||||
"""Extract and clamp ``limit`` / ``offset`` from the current request's query string."""
|
||||
limit = min(request.args.get("limit", default_limit, type=int), max_limit)
|
||||
offset = request.args.get("offset", 0, type=int)
|
||||
return limit, offset
|
||||
|
||||
Reference in New Issue
Block a user