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
|
|
@ -5,6 +5,8 @@ Endpoints:
|
|||
- List: Description
|
||||
- Endpoints: Description
|
||||
"""
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.params import Path
|
||||
from sqlalchemy.sql import exists
|
||||
|
|
@ -29,7 +31,7 @@ router = APIRouter(
|
|||
|
||||
|
||||
@router.get("/{org_id}/contact/{contact_type}", response_model=OrgContactGetResponse)
|
||||
async def get_contact(db: db_dependency, user: claims_dependency, is_org_admin: org_user_dependency, contact_type: ContactType, org_id: int = Path(gt=0)):
|
||||
async def get_contact(db: db_dependency, user: claims_dependency, is_admin: org_user_dependency, contact_type: ContactType, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = db.query(Org).filter(Org.id == org_id).first()
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ Endpoints:
|
|||
- [patch]/{contact_id} - Updates the details of an existing contact
|
||||
- [delete]/{contact_id} - Deletes a contact by ID
|
||||
"""
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.params import Path
|
||||
|
||||
|
|
@ -55,7 +57,7 @@ async def create_contact(db: db_dependency, contact_request: ContactContactPostR
|
|||
|
||||
|
||||
@router.patch("/{contact_id}")
|
||||
async def update_contact(db: db_dependency, contact_request: ContactUpdateRequest, contact_id: int = Path(gt=0)):
|
||||
async def update_contact(db: db_dependency, contact_request: ContactUpdateRequest, contact_id: Annotated[int, Path(gt=0)]):
|
||||
contact_model = (db.query(Contact).filter(Contact.id == contact_id).first())
|
||||
if contact_model is None:
|
||||
raise HTTPException(status_code=404, detail="Contact not found")
|
||||
|
|
@ -72,7 +74,7 @@ async def update_contact(db: db_dependency, contact_request: ContactUpdateReques
|
|||
|
||||
|
||||
@router.delete("/{contact_id}")
|
||||
async def delete_contact(db: db_dependency, contact_id: int = Path(gt=0)):
|
||||
async def delete_contact(db: db_dependency, contact_id: Annotated[int, Path(gt=0)]):
|
||||
contact_model = (db.query(Contact).filter(Contact.id == contact_id).first())
|
||||
if contact_model is None:
|
||||
raise HTTPException(status_code=404, detail="Contact not found")
|
||||
|
|
@ -82,7 +84,7 @@ async def delete_contact(db: db_dependency, contact_id: int = Path(gt=0)):
|
|||
|
||||
|
||||
@router.get("/{contact_id}/orgs", response_model=list[ContactOrgGetResponse])
|
||||
async def get_contact_orgs(db: db_dependency, contact_id: int = Path(gt=0)):
|
||||
async def get_contact_orgs(db: db_dependency, contact_id: Annotated[int, Path(gt=0)]):
|
||||
contact_model = (db.query(Contact).filter(Contact.id == contact_id).first())
|
||||
if contact_model is None:
|
||||
raise HTTPException(status_code=404, detail="Contact not found")
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ Endpoints:
|
|||
- [delete]/{org_id} - Deletes an organisation by ID
|
||||
- [get]/{org_id}/contact/{contact_type} - Retrieves the contact of a specific type (owner, billing, security) for an organisation
|
||||
"""
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.params import Path
|
||||
|
||||
|
|
@ -36,7 +38,7 @@ router = APIRouter(
|
|||
|
||||
|
||||
@router.get("/id/{org_id}", response_model=OrgOrgGetResponse)
|
||||
async def get_org_by_id(db: db_dependency, org_id: int = Path(gt=0)):
|
||||
async def get_org_by_id(db: db_dependency, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = (db.query(Org).filter(Org.id == org_id).first())
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -63,7 +65,7 @@ async def create_org(db: db_dependency, org_request: OrgOrgPostRequest):
|
|||
|
||||
|
||||
@router.patch("/{org_id}/questionnaire")
|
||||
async def update_questionnaire(db: db_dependency, q_request: OrgQuestionnairePatchRequest, org_id: int = Path(gt=0)):
|
||||
async def update_questionnaire(db: db_dependency, q_request: OrgQuestionnairePatchRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||
"""
|
||||
Route for updating questionnaire.
|
||||
The partial bool allows for submission of partially completed questionnaire and/or
|
||||
|
|
@ -84,7 +86,7 @@ async def update_questionnaire(db: db_dependency, q_request: OrgQuestionnairePat
|
|||
|
||||
|
||||
@router.patch("/{org_id}/status")
|
||||
async def update_status(db: db_dependency, status_request: OrgStatusPatchRequest, org_id: int = Path(gt=0)):
|
||||
async def update_status(db: db_dependency, status_request: OrgStatusPatchRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = db.query(Org).filter(Org.id == org_id).first()
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -96,7 +98,7 @@ async def update_status(db: db_dependency, status_request: OrgStatusPatchRequest
|
|||
|
||||
|
||||
@router.patch("/{org_id}/contact")
|
||||
async def update_contact(db: db_dependency, contact_request: OrgContactPatchRequest, org_id: int = Path(gt=0)):
|
||||
async def update_contact(db: db_dependency, contact_request: OrgContactPatchRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = db.query(Org).filter(Org.id == org_id).first()
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -116,7 +118,7 @@ async def update_contact(db: db_dependency, contact_request: OrgContactPatchRequ
|
|||
|
||||
|
||||
@router.get("/{org_id}/users", response_model=list[OrgUserGetResponse])
|
||||
async def get_users(db: db_dependency, org_id: int = Path(gt=0)):
|
||||
async def get_users(db: db_dependency, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_exists = db.query(exists().where(Org.id == org_id)).scalar()
|
||||
if not org_exists:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -127,7 +129,7 @@ async def get_users(db: db_dependency, org_id: int = Path(gt=0)):
|
|||
|
||||
|
||||
@router.get("/{org_id}/users/admins", response_model=list[OrgUserGetResponse])
|
||||
async def get_admin_users(db: db_dependency, org_id: int = Path(gt=0)):
|
||||
async def get_admin_users(db: db_dependency, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_exists = db.query(exists().where(Org.id == org_id)).scalar()
|
||||
if not org_exists:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -138,7 +140,7 @@ async def get_admin_users(db: db_dependency, org_id: int = Path(gt=0)):
|
|||
|
||||
|
||||
@router.post("/{org_id}/users")
|
||||
async def add_user_to_org(db: db_dependency, user_request: OrgUserPostRequest, org_id: int = Path(gt=0)):
|
||||
async def add_user_to_org(db: db_dependency, user_request: OrgUserPostRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_user_model = OrgUsers(**user_request.model_dump(), org_id=org_id)
|
||||
|
||||
db.add(org_user_model)
|
||||
|
|
@ -146,7 +148,7 @@ async def add_user_to_org(db: db_dependency, user_request: OrgUserPostRequest, o
|
|||
|
||||
|
||||
@router.patch("/{org_id}/users")
|
||||
async def update_user_details(db: db_dependency, user_request: OrgUserPostRequest, org_id: int = Path(gt=0)):
|
||||
async def update_user_details(db: db_dependency, user_request: OrgUserPostRequest, org_id: Annotated[int, Path(gt=0)]):
|
||||
"""
|
||||
Currently used only to update user admin status for organisation.
|
||||
"""
|
||||
|
|
@ -164,7 +166,7 @@ async def update_user_details(db: db_dependency, user_request: OrgUserPostReques
|
|||
|
||||
|
||||
@router.delete("/{org_id}")
|
||||
async def delete_organisation_by_id(db: db_dependency, org_id: int = Path(gt=0)):
|
||||
async def delete_organisation_by_id(db: db_dependency, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = (db.query(Org).filter(Org.id == org_id).first())
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
@ -173,7 +175,7 @@ async def delete_organisation_by_id(db: db_dependency, org_id: int = Path(gt=0))
|
|||
|
||||
|
||||
@router.get("/{org_id}/contact/{contact_type}", response_model=OrgContactGetResponse)
|
||||
async def get_contact(db: db_dependency, contact_type: ContactType, org_id: int = Path(gt=0)):
|
||||
async def get_contact(db: db_dependency, contact_type: ContactType, org_id: Annotated[int, Path(gt=0)]):
|
||||
org_model = db.query(Org).filter(Org.id == org_id).first()
|
||||
if org_model is None:
|
||||
raise HTTPException(status_code=404, detail="Organisation not found")
|
||||
|
|
|
|||
|
|
@ -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