Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(api): enforce fetch results to be ordered by ID #426

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def fetch_cameras(
token_payload: TokenPayload = Security(get_jwt, scopes=[UserRole.ADMIN, UserRole.AGENT, UserRole.USER]),
) -> List[Camera]:
telemetry_client.capture(token_payload.sub, event="cameras-fetch")
all_cameras = [elt for elt in await cameras.fetch_all()]
all_cameras = [elt for elt in await cameras.fetch_all(order_by="id")]
if UserRole.ADMIN in token_payload.scopes:
return all_cameras
return [camera for camera in all_cameras if camera.organization_id == token_payload.organization_id]
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/api_v1/endpoints/detections.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
cameras_list = await cameras.fetch_all(filters=("organization_id", token_payload.organization_id))
camera_ids = [camera.id for camera in cameras_list]

return await detections.fetch_all(in_pair=("camera_id", camera_ids))
return await detections.fetch_all(in_pair=("camera_id", camera_ids), order_by="id")

Check warning on line 197 in src/app/api/api_v1/endpoints/detections.py

View check run for this annotation

Codecov / codecov/patch

src/app/api/api_v1/endpoints/detections.py#L197

Added line #L197 was not covered by tests


@router.delete("/{detection_id}", status_code=status.HTTP_200_OK, summary="Delete a detection")
Expand Down
Loading