Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep FormDocuments up to date in V1 API calls #586

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

thomasiles
Copy link
Contributor

@thomasiles thomasiles commented Sep 27, 2024

This PR ensures that the V2 API models are updated from V1 API calls

Trello card: https://trello.com/c/l48nxEEO/1789-8-add-a-form-documents-table-to-forms-api

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

The table api_v2_form_documents uses form_id as a foreign key. Deleting
a form will raise an error if there are associated form_documents.

This commit adds a has_many association to the Form and
Api::V2::Form models. This ensures that any form_documents are deleting
before any Form is removed to that no error is thrown from the db.
Uses of the V1 API should update the V2 FormDocument so they can be
used in the responses from the V2 API.

This commit introduces a new class, awkwardly name ModelSync. This class
will be used in the V1 API to keep FormDocuments in sync.

It calls the conversion function with the contents of a form_blob and
creates, updates and deletes form_documents as needed.
The V1 API should also change the V2 API models.

This commit adds calls to the ModelSync class to update FormDocuments
during V1 API calls.
When creating, updating, moving and deleting pages, the draft form
document must be kept up to date. This will allow the V2 API to serve
matching form documents.
The V1 API needs to keep FormDocuments up to date.

This commit updates FormDocuments when forms are made live and archived.

Controller tests are added for the FormController but most of the work
happens within the state machine.

Calls to the ModelSync class are made on transistions.
Copy link

@thomasiles thomasiles marked this pull request as draft September 27, 2024 12:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant