Add created_at field to User and Item models and update endpoints (#2144)

This commit is contained in:
Alejandra
2026-01-23 16:18:22 +01:00
committed by GitHub
parent 2720308701
commit 3c1f7c4cdb
6 changed files with 78 additions and 2 deletions

View File

@@ -21,7 +21,9 @@ def read_items(
if current_user.is_superuser:
count_statement = select(func.count()).select_from(Item)
count = session.exec(count_statement).one()
statement = select(Item).offset(skip).limit(limit)
statement = (
select(Item).order_by(Item.created_at.desc()).offset(skip).limit(limit)
)
items = session.exec(statement).all()
else:
count_statement = (
@@ -33,6 +35,7 @@ def read_items(
statement = (
select(Item)
.where(Item.owner_id == current_user.id)
.order_by(Item.created_at.desc())
.offset(skip)
.limit(limit)
)

View File

@@ -42,7 +42,7 @@ def read_users(session: SessionDep, skip: int = 0, limit: int = 100) -> Any:
count_statement = select(func.count()).select_from(User)
count = session.exec(count_statement).one()
statement = select(User).offset(skip).limit(limit)
statement = select(User).order_by(User.created_at.desc()).offset(skip).limit(limit)
users = session.exec(statement).all()
return UsersPublic(data=users, count=count)