fix: corrected use of path param
Previously used `param: int = Path()` this worked but was incorrect. Correct usage is `param: Annotated[int, Path()]`
This commit is contained in:
parent
2b8296d622
commit
6f4556a44b
4 changed files with 24 additions and 16 deletions
|
|
@ -11,6 +11,8 @@ Endpoints:
|
|||
- [get]/{user_id}/orgs/admin - Retrieves only admin organisations for a specific user
|
||||
- [delete]/{user_id} - Deletes a user from the db by their db ID
|
||||
"""
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.params import Path
|
||||
from sqlalchemy.sql import exists
|
||||
|
|
@ -94,7 +96,7 @@ async def get_user_by_id(user_id: int, db: db_dependency):
|
|||
|
||||
|
||||
@router.get("/{user_id}/orgs", response_model=list[OrgResponse])
|
||||
async def get_organisations(db: db_dependency, user_id: int = Path(gt=0)):
|
||||
async def get_organisations(db: db_dependency, user_id: Annotated[int, Path(gt=0)]):
|
||||
user_exists = db.query(exists().where(User.id == user_id)).scalar()
|
||||
if not user_exists:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
|
@ -109,7 +111,7 @@ async def get_organisations(db: db_dependency, user_id: int = Path(gt=0)):
|
|||
|
||||
|
||||
@router.get("/{user_id}/orgs/admin", response_model=list[OrgResponse])
|
||||
async def get_admin_organisations(db: db_dependency, user_id: int = Path(gt=0)):
|
||||
async def get_admin_organisations(db: db_dependency, user_id: Annotated[int, Path(gt=0)]):
|
||||
user_exists = db.query(exists().where(User.id == user_id)).scalar()
|
||||
if not user_exists:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue