Skip to content

[Pipeline B] Apply routes → services → repositories layering to forms & templates #640

Description

@abhishek-8081

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 ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions