Skip to content

Commit

Permalink
feat: Sort collection API (#888)
Browse files Browse the repository at this point in the history
to have most recent items first
  • Loading branch information
Jagrutiti authored Sep 6, 2022
1 parent 7aff690 commit 275ef95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions robotoff/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def get_insights(

elif order_by == "n_votes":
query = query.order_by(ProductInsight.n_votes.desc())

if as_dict:
query = query.dicts()

Expand Down Expand Up @@ -201,6 +202,8 @@ def get_predictions(
if where_clauses:
query = query.where(*where_clauses)

query = query.order_by(Prediction.id.desc())

if count:
return query.count()
else:
Expand Down Expand Up @@ -244,6 +247,8 @@ def get_image_predictions(
if where_clauses:
query = query.where(*where_clauses)

query = query.order_by(LogoAnnotation.image_prediction.id.desc())

if count:
return query.count()
else:
Expand Down Expand Up @@ -372,6 +377,8 @@ def get_logo_annotation(
if offset is not None:
query = query.offset(offset)

query = query.order_by(LogoAnnotation.image_prediction.id.desc())

if count:
return query.count()
else:
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,8 @@ def test_logo_annotation_collection_empty(client):


def test_logo_annotation_collection_api(client):
LogoAnnotation.delete().execute() # remove default sample

annotation_123_1 = LogoAnnotationFactory(
image_prediction__image__barcode="123",
annotation_value_tag="etorki",
Expand Down

0 comments on commit 275ef95

Please sign in to comment.