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

Feature/pdct 671 add order by for all gets for families and collections to be on last edited #58

10 changes: 7 additions & 3 deletions app/repository/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from typing import Optional, Tuple, Union, cast

from sqlalchemy import Column, and_, or_
from sqlalchemy import Column, and_, desc, or_
from sqlalchemy import delete as db_delete
from sqlalchemy import update as db_update
from sqlalchemy.exc import NoResultFound, OperationalError
Expand Down Expand Up @@ -94,7 +94,7 @@ def all(db: Session) -> list[CollectionReadDTO]:
:param db Session: the database connection
:return Optional[CollectionResponse]: All of things
"""
collections = _get_query(db).all()
collections = _get_query(db).order_by(desc(Collection.last_modified)).all()

if not collections:
return []
Expand Down Expand Up @@ -145,7 +145,11 @@ def search(
condition = and_(*search) if len(search) > 1 else search[0]
try:
found = (
_get_query(db).filter(condition).limit(query_params["max_results"]).all()
_get_query(db)
.filter(condition)
.order_by(desc(Collection.last_modified))
.limit(query_params["max_results"])
.all()
)
except OperationalError as e:
if "canceling statement due to statement timeout" in str(e):
Expand Down
2 changes: 2 additions & 0 deletions app/repository/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def all(db: Session) -> list[DocumentReadDTO]:
:param db Session: the database connection
:return Optional[DocumentResponse]: All of things
"""
# TODO: PDCT-672 .Add ordering e.g., order_by(desc(FamilyDocument.last_modified))
result = _get_query(db).all()

if not result:
Expand Down Expand Up @@ -183,6 +184,7 @@ def search(

condition = and_(*search) if len(search) > 1 else search[0]
try:
# TODO: Fix order by on search PDCT-672
result = (
_get_query(db).filter(condition).limit(query_params["max_results"]).all()
)
Expand Down
10 changes: 7 additions & 3 deletions app/repository/family.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime
from typing import Optional, Tuple, Union, cast

from sqlalchemy import Column, and_, or_
from sqlalchemy import Column, and_, desc, or_
from sqlalchemy import delete as db_delete
from sqlalchemy import update as db_update
from sqlalchemy.exc import NoResultFound, OperationalError
Expand Down Expand Up @@ -133,7 +133,7 @@ def all(db: Session) -> list[FamilyReadDTO]:
:param db Session: the database connection
:return Optional[FamilyResponse]: All of things
"""
family_geo_metas = _get_query(db).all()
family_geo_metas = _get_query(db).order_by(desc(Family.last_modified)).all()

if not family_geo_metas:
return []
Expand Down Expand Up @@ -203,7 +203,11 @@ def search(
condition = and_(*search) if len(search) > 1 else search[0]
try:
found = (
_get_query(db).filter(condition).limit(query_params["max_results"]).all()
_get_query(db)
.filter(condition)
.order_by(desc(Family.last_modified))
.limit(query_params["max_results"])
.all()
)
except OperationalError as e:
if "canceling statement due to statement timeout" in str(e):
Expand Down
Loading