From f95a2c427e9a73bdddee971f1106f051ba26117b Mon Sep 17 00:00:00 2001 From: Esteban Maya Cadavid Date: Tue, 12 Mar 2024 13:14:55 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20items=20count=20when?= =?UTF-8?q?=20retrieving=20data=20for=20all=20items=20by=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/routes/items.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index ddbe93eef5..ab72bbd3e8 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -17,13 +17,16 @@ 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) From d4d54c53c1149d5fb5b5f5fcf25eaba3da47d510 Mon Sep 17 00:00:00 2001 From: Esteban Maya Cadavid Date: Tue, 12 Mar 2024 13:20:26 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=8E=A8=20Format=20code=20applied?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/routes/items.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/app/api/routes/items.py b/backend/app/api/routes/items.py index ab72bbd3e8..e325e9b345 100644 --- a/backend/app/api/routes/items.py +++ b/backend/app/api/routes/items.py @@ -23,8 +23,10 @@ def read_items( 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 + statment = ( + select(func.count()) + .select_from(Item) + .where(Item.owner_id == current_user.id) ) count = session.exec(statment).one() statement = (