Switching to the registry paradigm
This commit is contained in:
@@ -2,7 +2,7 @@ from beanie import PydanticObjectId
|
||||
from fastapi import HTTPException, Depends
|
||||
|
||||
from firm.core.routes import get_crud_router
|
||||
from firm.core.depends import get_logged_tenant_db_cursor
|
||||
from firm.core.depends import get_authed_tenant_registry
|
||||
|
||||
from firm.contract.models import ContractDraft, ContractDraftStatus, ContractDraftFilters
|
||||
from firm.contract.schemas import ContractDraftCreate, ContractDraftRead, ContractDraftUpdate
|
||||
@@ -14,17 +14,17 @@ del(draft_router.routes[1]) #post route
|
||||
|
||||
|
||||
@draft_router.post("/", response_description="Contract Draft added to the database")
|
||||
async def create(schema: ContractDraftCreate, db=Depends(get_logged_tenant_db_cursor)) -> ContractDraftRead:
|
||||
await schema.validate_foreign_key(db)
|
||||
record = await ContractDraft.create(db, schema)
|
||||
await record.check_is_ready(db)
|
||||
async def create(schema: ContractDraftCreate, reg=Depends(get_authed_tenant_registry)) -> ContractDraftRead:
|
||||
await schema.validate_foreign_key(reg.db)
|
||||
record = await ContractDraft.create(reg.db, schema)
|
||||
await record.check_is_ready(reg.db)
|
||||
|
||||
return ContractDraftRead.from_model(record)
|
||||
|
||||
|
||||
@draft_router.put("/{record_id}", response_description="Contract Draft record updated")
|
||||
async def update(record_id: PydanticObjectId, schema: ContractDraftUpdate, db=Depends(get_logged_tenant_db_cursor)) -> ContractDraftRead:
|
||||
record = await ContractDraft.get(db, record_id)
|
||||
async def update(record_id: PydanticObjectId, schema: ContractDraftUpdate, reg=Depends(get_authed_tenant_registry)) -> ContractDraftRead:
|
||||
record = await ContractDraft.get(reg.db, record_id)
|
||||
if not record:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
@@ -36,7 +36,7 @@ async def update(record_id: PydanticObjectId, schema: ContractDraftUpdate, db=De
|
||||
detail="Contract Draft has already been published"
|
||||
)
|
||||
|
||||
record = await ContractDraft.update(db, record, schema)
|
||||
await record.check_is_ready(db)
|
||||
record = await ContractDraft.update(reg.db, record, schema)
|
||||
await record.check_is_ready(reg.db)
|
||||
|
||||
return ContractDraftRead.from_model(record)
|
||||
|
||||
Reference in New Issue
Block a user