Files
roleplay-contract/api/rpk-api/firm/current_firm/routes.py

23 lines
1.3 KiB
Python

from fastapi import APIRouter, Depends
from firm.core.depends import get_logged_tenant_db_cursor, get_uninitialized_tenant_db_cursor
from firm.current_firm import CurrentFirmModel, CurrentFirmSchemaRead, CurrentFirmSchemaCreate, CurrentFirmSchemaUpdate
current_firm_router = APIRouter()
@current_firm_router.get("/", response_model=CurrentFirmSchemaRead, response_description=f"Current Firm records retrieved")
async def read(db=Depends(get_logged_tenant_db_cursor)) -> CurrentFirmSchemaRead:
return CurrentFirmSchemaRead.from_model(**CurrentFirmModel.get(db))
@current_firm_router.post("/", response_description=f"Current Firm added to the database")
async def create(schema: CurrentFirmSchemaCreate, db=Depends(get_uninitialized_tenant_db_cursor)) -> CurrentFirmSchemaRead:
await schema.validate_foreign_key(db)
record = await CurrentFirmModel.create(db, schema)
return CurrentFirmSchemaRead.from_model(record)
@current_firm_router.put("/", response_description=f"Current Firm record updated")
async def update(schema: CurrentFirmSchemaUpdate, db=Depends(get_logged_tenant_db_cursor)) -> CurrentFirmSchemaRead:
record = await CurrentFirmModel.get(db)
record = await CurrentFirmModel.update(db, record, schema)
return CurrentFirmSchemaRead.from_model(record)