From 98c78e4683bea92b84146c47bc68e4a5681466e1 Mon Sep 17 00:00:00 2001 From: Esteban Maya Date: Tue, 12 Mar 2024 13:23:33 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20items=20count=20when=20r?= =?UTF-8?q?etrieving=20data=20for=20all=20items=20by=20user=20(#695)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/routes/items.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index ddbe93e..e325e9b 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -17,13 +17,18 @@ def read_items( Retrieve items. """ - statment = select(func.count()).select_from(Item) - count = session.exec(statment).one() - if current_user.is_superuser: + statment = select(func.count()).select_from(Item) + count = session.exec(statment).one() statement = select(Item).offset(skip).limit(limit) items = session.exec(statement).all() else: + statment = ( + select(func.count()) + .select_from(Item) + .where(Item.owner_id == current_user.id) + ) + count = session.exec(statment).one() statement = ( select(Item) .where(Item.owner_id == current_user.id)