Skip to content

[BUG] - Make use of dependencies.py #50

@zdomke

Description

@zdomke

Describe the bug

The backend has a file containing all of the dependencies for our endpoints, but for some reason we aren't using the dependencies.

dependencies.py looks good and could be used, but instead we are making the services in each endpoint unnecessarily. Examples below:

service = PVService(db)

service = SnapshotService(db, epics)

service = TagService(db)

Expected behavior

All endpoints should make use of these dependencies instead of using the get_db dependency and creating the service themselves.

Steps to Reproduce

n/a

Possible solution (optional)

Old

async def create_tag_group(data: TagGroupCreate, db: AsyncSession = Depends(get_db)):
"""Create a new tag group."""
service = TagService(db)
try:
group = await service.create_group(data)
return success_response(group)
except ValueError as e:
raise APIException(409, str(e), 409)

New

async def create_tag_group(data: TagGroupCreate, service: TagService = Depends(get_tag_service)):
    """Create a new tag group."""
    try:
        group = await service.create_group(data)
        return success_response(group)
    except ValueError as e:
        raise APIException(409, str(e), 409)

My platform

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions