learnhouse/apps/api/src/routers/install/install.py
2023-11-20 22:38:49 +01:00

71 lines
1.9 KiB
Python

from fastapi import APIRouter, Depends, Request
from src.core.events.database import get_db_session
from src.db.organizations import OrganizationCreate
from src.db.users import UserCreate
from src.services.install.install import (
create_install_instance,
get_latest_install_instance,
install_create_organization,
install_create_organization_user,
install_default_elements,
update_install_instance,
)
router = APIRouter()
@router.post("/start")
async def api_create_install_instance(
request: Request, data: dict, db_session=Depends(get_db_session),
):
# create install
install = await create_install_instance(request, data, db_session)
return install
@router.get("/latest")
async def api_get_latest_install_instance(request: Request, db_session=Depends(get_db_session),):
# get latest created install
install = await get_latest_install_instance(request, db_session=db_session)
return install
@router.post("/default_elements")
async def api_install_def_elements(request: Request, db_session=Depends(get_db_session),):
elements = await install_default_elements(request, {}, db_session)
return elements
@router.post("/org")
async def api_install_org(
request: Request, org: OrganizationCreate, db_session=Depends(get_db_session),
):
organization = await install_create_organization(request, org, db_session)
return organization
@router.post("/user")
async def api_install_user(
request: Request, data: UserCreate, org_slug: str, db_session=Depends(get_db_session),
):
user = await install_create_organization_user(request, data, org_slug, db_session)
return user
@router.post("/update")
async def api_update_install_instance(
request: Request, data: dict, step: int, db_session=Depends(get_db_session),
):
request.app.db["installs"]
# get latest created install
install = await update_install_instance(request, data, step, db_session)
return install