58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
import asyncio
|
|
import fastapi
|
|
import pydantic
|
|
|
|
from app.storage.mongo import configs
|
|
from app.storage.mongo import experiments
|
|
from app.storage.mongo import staff
|
|
|
|
|
|
class ExperimentData(pydantic.BaseModel):
|
|
enabled: bool
|
|
condition: str
|
|
|
|
|
|
class PlatformStaff(pydantic.BaseModel):
|
|
vk_id: list[int]
|
|
yandex_id: list[int]
|
|
telegram_id: list[int]
|
|
email: list[str]
|
|
|
|
|
|
class ResponseBody(pydantic.BaseModel):
|
|
configs: dict[str, dict]
|
|
experiments: dict[str, ExperimentData]
|
|
platform_staff: PlatformStaff
|
|
|
|
|
|
router = fastapi.APIRouter()
|
|
|
|
|
|
@router.post('/api/v1/fetch')
|
|
async def execute(stage: str, project: str):
|
|
confs, exps, staffs = await asyncio.gather(
|
|
configs.get(project=project, stage=stage),
|
|
experiments.get(project=project, stage=stage),
|
|
staff.get(),
|
|
)
|
|
platform_staff = PlatformStaff(
|
|
vk_id=[],
|
|
yandex_id=[],
|
|
telegram_id=[],
|
|
email=[],
|
|
)
|
|
for user in staffs:
|
|
if user.vk_id:
|
|
platform_staff.vk_id.append(user.vk_id)
|
|
if user.yandex_id:
|
|
platform_staff.yandex_id.append(user.yandex_id)
|
|
if user.telegram_id:
|
|
platform_staff.telegram_id.append(user.telegram_id)
|
|
if user.email:
|
|
platform_staff.email.append(user.email)
|
|
return ResponseBody(
|
|
configs={conf.name: conf.value for conf in confs},
|
|
experiments={exp.name: ExperimentData(enabled=exp.enabled, condition=exp.condition) for exp in exps},
|
|
platform_staff=platform_staff,
|
|
)
|