2026-04-06 12:41:49 +01:00
|
|
|
"""
|
|
|
|
|
Router dependencies for organisation module
|
|
|
|
|
|
|
|
|
|
Classes:
|
|
|
|
|
- List: Description
|
|
|
|
|
- Classes: Description
|
|
|
|
|
|
|
|
|
|
Functions:
|
|
|
|
|
- List: Description
|
|
|
|
|
- Functions: Description
|
2026-05-25 09:05:17 +01:00
|
|
|
"""
|
|
|
|
|
from typing import Annotated
|
|
|
|
|
|
2026-05-27 12:21:03 +01:00
|
|
|
from fastapi import Depends, Query
|
2026-05-25 09:05:17 +01:00
|
|
|
|
|
|
|
|
from src.database import db_dependency
|
|
|
|
|
|
2026-05-27 12:21:03 +01:00
|
|
|
from src.organisation.schemas import OrgIDMixin
|
2026-05-25 09:05:17 +01:00
|
|
|
from src.organisation.models import Organisation as Org
|
2026-05-27 12:21:03 +01:00
|
|
|
from src.organisation.exceptions import OrgNotFoundException
|
2026-05-25 09:05:17 +01:00
|
|
|
|
|
|
|
|
|
2026-05-27 12:21:03 +01:00
|
|
|
def get_org_model_query(db: db_dependency, org_id: Annotated[int, Query(gt=0)]) -> type[Org]:
|
|
|
|
|
org_model = db.get(Org, org_id)
|
2026-05-25 09:05:17 +01:00
|
|
|
if org_model is None:
|
2026-05-27 12:21:03 +01:00
|
|
|
raise OrgNotFoundException(org_id)
|
2026-05-25 09:05:17 +01:00
|
|
|
|
|
|
|
|
return org_model
|
|
|
|
|
|
2026-05-27 12:21:03 +01:00
|
|
|
org_model_query_dependency = Annotated[type[Org], Depends(get_org_model_query)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_org_model_body(db: db_dependency, request_model: OrgIDMixin) -> type[Org]:
|
|
|
|
|
org_id = getattr(request_model, "organisation_id", None)
|
|
|
|
|
if org_id is None:
|
|
|
|
|
raise OrgNotFoundException
|
|
|
|
|
org_model = db.get(Org, org_id)
|
|
|
|
|
if org_model is None:
|
|
|
|
|
raise OrgNotFoundException(org_id)
|
|
|
|
|
|
|
|
|
|
return org_model
|
|
|
|
|
|
|
|
|
|
org_model_body_dependency = Annotated[type[Org], Depends(get_org_model_body)]
|