From c13c9ebbbb0e28619a44aa4829b15ee08fce819c Mon Sep 17 00:00:00 2001 From: Parker Date: Fri, 8 Nov 2024 15:07:11 -0600 Subject: [PATCH] Order links by date descending when returned --- app/routes/links_routes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/routes/links_routes.py b/app/routes/links_routes.py index f56ebfc..833c699 100644 --- a/app/routes/links_routes.py +++ b/app/routes/links_routes.py @@ -21,7 +21,13 @@ async def get_links( current_user: Annotated[User, Depends(get_current_user)], db=Depends(get_db), ): - links = db.query(Link).filter(Link.owner == current_user.id).all() + # Get and sort links by expiration date descending + links = ( + db.query(Link) + .filter(Link.owner == current_user.id) + .order_by(Link.expire_date.desc()) + .all() + ) if not links: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail="No links found"