[loggi-klf] DRY stats endpoint boilerplate with a shared helper #117
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Bead ID:
loggi-klfType: task
Priority: P2
Status: closed
Close reason: Extracted _get_entry_and_base_query() helper in stats.py that handles entry lookup, access check (404/403), and date-filtered base query construction. All 6 stats endpoints now use this instead of repeating ~10 lines of boilerplate each. Cleaned up unused imports. All 171 tests pass.
Why
All 6 stats endpoints in stats.py repeat the same 10-line preamble: get entry, check not found (404), check access (403), parse from/to params, build base query with date filters. That's ~60 lines of pure duplication and a maintenance risk.
What
Extract a helper function like _stats_base_query(entry_id) that:
Each endpoint replaces its boilerplate with a single call to this helper. On error, the helper returns a Flask response tuple; on success, it returns (entry, base_query).
Acceptance criteria
Dependencies:
loggi-2ze