43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import bson
|
|
import fastapi
|
|
import pydantic
|
|
|
|
from app.storage.mongo import configs
|
|
|
|
|
|
class RequestPostBody(pydantic.BaseModel):
|
|
name: str
|
|
stage: str
|
|
project: str
|
|
|
|
|
|
class RequestPutBody(pydantic.BaseModel):
|
|
id: str
|
|
value: dict
|
|
|
|
|
|
class RequestDeleteBody(pydantic.BaseModel):
|
|
id: str
|
|
|
|
|
|
router = fastapi.APIRouter()
|
|
|
|
|
|
@router.post('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED)
|
|
async def post(body: RequestPostBody):
|
|
await configs.create(configs.Config(name=body.name, project=body.project, stage=body.stage, value={}))
|
|
|
|
|
|
@router.put('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
|
async def put(body: RequestPutBody):
|
|
changed = await configs.update_data(id=bson.ObjectId(body.id), value=body.value)
|
|
if not changed:
|
|
raise fastapi.HTTPException(404)
|
|
|
|
|
|
@router.delete('/api/v1/configs', status_code=fastapi.status.HTTP_202_ACCEPTED, responses={404: {'description': 'Not found'}})
|
|
async def delete(body: RequestDeleteBody):
|
|
changed = await configs.delete(id=bson.ObjectId(body.id))
|
|
if not changed:
|
|
raise fastapi.HTTPException(404)
|