Refactor inventory listing filters to return error messages for invalid user, location, and item IDs
This commit is contained in:
parent
0a5518d99f
commit
0835248f34
6 changed files with 11 additions and 7 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
__pycache__/
|
||||
.venv/
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
routes.py
17
routes.py
|
@ -158,15 +158,18 @@ def list_inventory():
|
|||
if column is not None:
|
||||
filter_name = None
|
||||
if filter_by == 'user':
|
||||
user = db.session.query(User).filter(User.id == id).first()
|
||||
filter_name = user.full_name if user else "Unknown User"
|
||||
if not (user := db.session.query(User).filter(User.id == id).first()):
|
||||
return "Invalid User ID", 400
|
||||
filter_name = user.full_name
|
||||
elif filter_by == 'location':
|
||||
room = db.session.query(Room).filter(Room.id == id).first()
|
||||
filter_name = room.full_name if room else "Unknown Location"
|
||||
if not (room := db.session.query(Room).filter(Room.id == id).first()):
|
||||
return "Invalid Location ID", 400
|
||||
filter_name = room.full_name
|
||||
else:
|
||||
item = db.session.query(Item).filter(Item.id == id).first()
|
||||
filter_name = item.description if item else "Unknown Item"
|
||||
|
||||
if not (item := db.session.query(Item).filter(Item.id == id).first()):
|
||||
return "Invalid Type ID", 400
|
||||
filter_name = item.description
|
||||
|
||||
query = query.filter(column == id)
|
||||
else:
|
||||
return "Invalid filter_by parameter", 400
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue