2026-04-06 12:41:49 +01:00
|
|
|
"""
|
|
|
|
|
Router endpoints for the admin module
|
|
|
|
|
|
|
|
|
|
Endpoints:
|
|
|
|
|
- List: Description
|
|
|
|
|
- Endpoints: Description
|
|
|
|
|
"""
|
2026-05-19 11:11:03 +01:00
|
|
|
from typing import Annotated
|
|
|
|
|
|
2026-04-06 12:41:49 +01:00
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
|
from fastapi.params import Path
|
|
|
|
|
from sqlalchemy.sql import exists
|
|
|
|
|
|
|
|
|
|
from src.organisation.constants import ContactType
|
|
|
|
|
from src.organisation.schemas import OrgContactGetResponse
|
|
|
|
|
from src.organisation.models import Organisation as Org
|
|
|
|
|
from src.contact.models import Contact
|
|
|
|
|
from src.user.models import User
|
|
|
|
|
from src.user.schemas import UserResponse, OIDCUser, OrgResponse
|
|
|
|
|
|
|
|
|
|
from src.organisation.models import OrgUsers, Organisation
|
|
|
|
|
|
|
|
|
|
from src.auth.service import claims_dependency, org_user_dependency, org_admin_dependency
|
|
|
|
|
from src.database import db_dependency
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router = APIRouter(
|
|
|
|
|
tags=["admin"],
|
|
|
|
|
prefix="/admin",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/{org_id}/contact/{contact_type}", response_model=OrgContactGetResponse)
|
2026-05-19 11:11:03 +01:00
|
|
|
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)]):
|
2026-04-06 12:41:49 +01:00
|
|
|
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")
|
|
|
|
|
match contact_type:
|
|
|
|
|
case "billing":
|
|
|
|
|
contact_id = org_model.billing_contact_id
|
|
|
|
|
case "security":
|
|
|
|
|
contact_id = org_model.security_contact_id
|
|
|
|
|
case "owner":
|
|
|
|
|
contact_id = org_model.owner_contact_id
|
|
|
|
|
case _:
|
|
|
|
|
raise HTTPException(status_code=422, detail="Invalid contact type")
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
|
|
|
|
|
return contact_model
|