feat: condensed org get endpoints

The process also added improved ORM relationships for multiple models.
This commit is contained in:
Chris Milne 2026-05-25 12:40:28 +01:00
parent a80767d870
commit 707482adc2
3 changed files with 8 additions and 12 deletions

View file

@ -38,17 +38,14 @@ router = APIRouter(
@router.get("/id/{org_id}", response_model=OrgOrgGetResponse)
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")
async def get_org_by_id(db: db_dependency, org_model: org_model_dependency, org_id: Annotated[int, Path(gt=0)]):
response = {
"name": org_model.name,
"status": org_model.status,
"owner_contact": (db.query(Contact).filter(Contact.id == org_model.owner_contact_id).first()),
"billing_contact": (db.query(Contact).filter(Contact.id == org_model.billing_contact_id).first()),
"security_contact": (db.query(Contact).filter(Contact.id == org_model.security_contact_id).first()),
"root_user": org_model.root_user_email
}
return response
@ -173,13 +170,6 @@ async def get_contact(db: db_dependency, contact_type: ContactType, org_id: Anno
return contact_model
@router.get("/{org_id}/root_user")
async def get_org_root_user(db: db_dependency, org_model: org_model_dependency, org_id: Annotated[int, Path(gt=0)]):
root_user = org_model.root_user_id
return {"root_user": root_user}
@router.patch("/{org_id}/root_user")
async def update_root_user(db: db_dependency, org_model: org_model_dependency, org_id: Annotated[int, Path(gt=0)], root_user: Annotated[int, Query(gt=0)]):
# TODO: Request model, ditch query