Skip to content

FIX: Use dependencies.py service factories in API handlers#75

Open
YektaY wants to merge 2 commits intomainfrom
yektay/api-changes
Open

FIX: Use dependencies.py service factories in API handlers#75
YektaY wants to merge 2 commits intomainfrom
yektay/api-changes

Conversation

@YektaY
Copy link
Copy Markdown
Collaborator

@YektaY YektaY commented Apr 22, 2026

Description

  • Replace inline service = FooService(db) construction in every app/api/v1/*.py handler with Depends(get_xxx_service) from app/dependencies.py.
  • Add two missing factories to app/dependencies.py: get_api_key_service and get_job_service.
  • Extend get_snapshot_service to pass the Redis singleton, removing a hand-rolled SnapshotService(db, epics, redis) in the sync snapshot-creation path.
  • Drop a dead service = PVService(db) line in GET /v1/pvs/search (the local variable was never used).

Motivation

app/dependencies.py already defined get_pv_service, get_snapshot_service, and get_tag_service, but handlers ignored them and re-instantiated services inline on every request — see examples in app/api/v1/tags.py and app/api/v1/snapshots.py before this change. That pattern made each handler carry extra boilerplate, obscured the real dependency graph, and made it harder to swap services in tests (the test fixtures already override get_db and get_epics_service, and Depends-style factories let those overrides cascade automatically).

This PR is a pure refactor: observable behavior is unchanged, so the full integration test suite passes without any test-side edits. It also lays groundwork for the follow-up envelope-removal work in #32 / slaclab/react-squirrel#77 — that PR touches every endpoint once, and having them all already go through Depends(get_xxx_service) means the diff per handler stays small.

Closes #50.

Where Has This Been Documented?

This change is internal refactoring with no user-visible surface change, so no doc updates were needed. The new factory names are self-documenting via their existing neighbors in app/dependencies.py.

Pre-merge checklist

  • Code works interactively
  • Code contains descriptive docstrings
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions

@YektaY YektaY self-assigned this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] - Make use of dependencies.py

1 participant