import fastapi import pydantic from app.storage.mongo import experiments class RequestPostBody(pydantic.BaseModel): name: str stage: str project: str class RequestPutBody(pydantic.BaseModel): name: str stage: str project: str enabled: bool condition: str router = fastapi.APIRouter() @router.post('/api/v1/experiments', status_code=fastapi.status.HTTP_202_ACCEPTED) async def post(body: RequestPostBody): await experiments.create(experiments.Experiment(name=body.name, project=body.project, stage=body.stage, enabled=False, condition='False')) @router.put('/api/v1/experiments', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}}) async def put(body: RequestPutBody): changed = await experiments.update(project=body.project, stage=body.stage, name=body.name, enabled=body.enabled, condition=body.condition) if not changed: raise fastapi.HTTPException(404) @router.delete('/api/v1/experiments', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}}) async def delete(body: RequestPostBody): changed = await experiments.delete(project=body.project, stage=body.stage, name=body.name) if not changed: raise fastapi.HTTPException(404)