mirror of
https://github.com/grey-cat-1908/formaptix-server.git
synced 2024-11-11 18:57:27 +03:00
createform response model
This commit is contained in:
parent
62ec226a26
commit
69e21b1290
1 changed files with 7 additions and 3 deletions
|
@ -2,14 +2,18 @@ from fastapi import APIRouter
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
|
||||||
import database
|
import database
|
||||||
from models import FormData, Form
|
from models import FormData, Form, BaseModel
|
||||||
from .utils import User
|
from .utils import User
|
||||||
|
|
||||||
router = APIRouter(prefix="/form")
|
router = APIRouter(prefix="/form")
|
||||||
|
|
||||||
|
|
||||||
|
class CreateForm(BaseModel):
|
||||||
|
form_id: int
|
||||||
|
|
||||||
|
|
||||||
@router.post("/create")
|
@router.post("/create")
|
||||||
async def create_form(user: User, form_data: FormData):
|
async def create_form(user: User, form_data: FormData) -> CreateForm:
|
||||||
async with database.sessions.begin() as session:
|
async with database.sessions.begin() as session:
|
||||||
form = database.Form(
|
form = database.Form(
|
||||||
name=form_data.name, owner_id=user.id, data=form_data.model_dump()
|
name=form_data.name, owner_id=user.id, data=form_data.model_dump()
|
||||||
|
@ -19,7 +23,7 @@ async def create_form(user: User, form_data: FormData):
|
||||||
await session.flush()
|
await session.flush()
|
||||||
await session.refresh(form)
|
await session.refresh(form)
|
||||||
|
|
||||||
return {"status": "success", "form_id": form.id}
|
return CreateForm(form_id=form.id)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/my")
|
@router.get("/my")
|
||||||
|
|
Loading…
Reference in a new issue