The forms and templates routes don't follow the routes → services → repositories layering
used elsewhere in the v1 API (#546/#547). routes/forms.py and routes/templates.py call the
Controller directly and run ad-hoc DB queries inline in the route (e.g. get_submissions,
get_submissions_analytics build select() statements in the route itself).
Changes
- Introduce a FormService and TemplateService (class-based, following the existing service
pattern) holding the business logic.
- Move all inline DB queries out of the routes into repository functions in
repositories.py.
- Routes become thin: parse → call service → return; HTTP concerns (status codes,
AppError) stay at the route.
Acceptance criteria
- No direct DB queries (select/add/commit) in routes/forms.py or routes/templates.py.
- FormService / TemplateService hold the logic; repositories.py holds the DB ops.
- Behavior unchanged; existing tests pass (adjusted for the new structure).
Part of the Pipeline B tracker (#636 ).
The forms and templates routes don't follow the routes → services → repositories layering
used elsewhere in the v1 API (#546/#547). routes/forms.py and routes/templates.py call the
Controller directly and run ad-hoc DB queries inline in the route (e.g. get_submissions,
get_submissions_analytics build select() statements in the route itself).
Changes
pattern) holding the business logic.
repositories.py.
AppError) stay at the route.
Acceptance criteria
Part of the Pipeline B tracker (#636 ).