Skip to content

[FEAT]: Add DELETE and PATCH endpoints for Template management #492

@arvinder004

Description

@arvinder004

name: 🚀 Feature Request
about: Suggest an idea or a new capability for FireForm.
title: "[FEAT]: Add DELETE and PATCH endpoints for Template management"
labels: enhancement
assignees: ''


📝 Description

The Templates API only supports creating and listing templates. There is no way
to delete a stale template or update its name and fields. Once a template is
created, it is permanent — even if the underlying PDF changes or the template
was created with incorrect field mappings.

api/db/repositories.py currently defines:

  • create_template() — write only
  • get_template() — single read
  • list_templates() — list read

There is no delete_template() or update_template().

💡 Rationale

Fire departments iterate on their PDF forms. A template registered with wrong
field names, a renamed PDF, or an outdated agency form has no removal path
today. Stale templates accumulate in the database and appear in the frontend
template list, causing confusion for responders selecting a form to fill.

🛠️ Proposed Solution

  • Add delete_template(session, template_id) to api/db/repositories.py
    — hard delete, returns 404 if not found
  • Add update_template(session, template_id, patch) to
    api/db/repositories.py — partial update of name and/or fields
  • Add DELETE /templates/{id} route — returns 204 on success, 404 if not found
  • Add PATCH /templates/{id} route — accepts partial TemplateUpdate
    schema, returns updated TemplateResponse
  • Add TemplateUpdate Pydantic schema with optional name and fields
  • Wire Delete and Edit buttons into the frontend template cards in app.js

✅ Acceptance Criteria

  • DELETE /templates/{id} removes the template and returns 204
  • DELETE /templates/{id} returns 404 for a non-existent ID
  • PATCH /templates/{id} updates only the provided fields and returns
    the updated template
  • PATCH /templates/{id} returns 404 for a non-existent ID
  • Frontend template cards show a Delete button alongside Preview and
    Use in Fill Form
  • No breaking changes to POST /templates/create or GET /templates
  • Tests cover all new endpoints
  • Feature works in Docker container

📌 Additional Context

api/errors/base.py already has AppError with status_code support, so
404 handling follows the existing pattern. TemplateUpdate should use
Optional fields so callers can patch name-only or fields-only without
sending the full object.

Happy to work on this if there's interest. @marcvergees

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions