Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions api/routes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

@router.post("/fill", response_model=FormFillResponse)
def fill_form(form: FormFill, db: Session = Depends(get_db)):
if not get_template(db, form.template_id):
raise AppError("Template not found", status_code=404)

fetched_template = get_template(db, form.template_id)

if not fetched_template:
raise AppError("Template not found", status_code=404)
controller = Controller()
path = controller.fill_form(user_input=form.input_text, fields=fetched_template.fields, pdf_form_path=fetched_template.pdf_path)

path = controller.fill_form(
user_input=form.input_text,
fields=fetched_template.fields,
pdf_form_path=fetched_template.pdf_path
)
submission = FormSubmission(**form.model_dump(), output_pdf_path=path)
return create_form(db, submission)

Expand Down
8 changes: 7 additions & 1 deletion api/schemas/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from pydantic import BaseModel
from pydantic import BaseModel, field_validator

class FormFill(BaseModel):
template_id: int
input_text: str

@field_validator("input_text")
def validate_input_text(cls, value):
if not value or not value.strip():
raise ValueError("Input text cannot be empty")
return value


class FormFillResponse(BaseModel):
id: int
Expand Down