@router.get('/{item_id}',response_model=Item,status_code=status.HTTP_200_OK)
def get_item(item_id:int):
item = db.query(models.Item).filter(models.Item.id==item_id).first()
return item
@router.get('/{category}',response_model=List[Item],status_code=status.HTTP_200_OK)
def get_items_by_category(category:str):
items = db.query(models.Item).where(models.Item.category==category).all()
return items
I created basic API's with FastAPI and also I wanna create categorical query with upper code. But when I try to run category query at Swagger, it says
{
"detail": [
{
"loc": [
"path",
"item_id"
],
"msg": "value is not a valid integer",
"type": "type_error.integer"
}
]
}
I wanna both Id(int) query and Categorical(str) query at same "/items" path. How can I do that? (Other files and code is correct. When I change the category parth, it works but I wanna do this at same path as I say).