Order links by date descending when returned

This commit is contained in:
Parker M. 2024-11-08 15:07:11 -06:00
parent f1411191b0
commit c13c9ebbbb
Signed by: parker
GPG Key ID: 505ED36FC12B5D5E

View File

@ -21,7 +21,13 @@ async def get_links(
current_user: Annotated[User, Depends(get_current_user)], current_user: Annotated[User, Depends(get_current_user)],
db=Depends(get_db), 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: if not links:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="No links found" status_code=status.HTTP_404_NOT_FOUND, detail="No links found"