Step 9:药品管理(IMP)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import uuid
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.deps import get_db_session, require_study_member
|
||||
from app.crud import imp_inventory as inventory_crud
|
||||
from app.crud import study as study_crud
|
||||
from app.schemas.imp import InventoryRead
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
async def _ensure_study_exists(db: AsyncSession, study_id: uuid.UUID):
|
||||
study = await study_crud.get(db, study_id)
|
||||
return study
|
||||
|
||||
|
||||
@router.get(
|
||||
"/",
|
||||
response_model=list[InventoryRead],
|
||||
dependencies=[Depends(require_study_member())],
|
||||
)
|
||||
async def list_inventory(
|
||||
study_id: uuid.UUID,
|
||||
site_id: uuid.UUID | None = None,
|
||||
product_id: uuid.UUID | None = None,
|
||||
db: AsyncSession = Depends(get_db_session),
|
||||
) -> list[InventoryRead]:
|
||||
await _ensure_study_exists(db, study_id)
|
||||
inv = await inventory_crud.list_inventory(db, study_id, site_id=site_id, product_id=product_id)
|
||||
return [InventoryRead.model_validate(i) for i in inv]
|
||||
Reference in New Issue
Block a user