Skip to content

Commit

Permalink
refactor(api): enforce fetch results to be ordered by ID (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
frgfm authored Feb 10, 2025
1 parent d70b389 commit d7a84bf
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
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 @@ async def fetch_detections(
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")


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

0 comments on commit d7a84bf

Please sign in to comment.