Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #636
Apologies for the delay! Please let me know if you'd like any modifications before submitting, or if you need any other endpoints for the frontend.
What changes did you make?
This PR introduces a basic forms API, with four main endpoints:
/forms
-> Create a new form./forms/{form_id}
-> Get the form definition/responses/{form_id}
-> Get the user's responses for a given form/responses/{form_id}
-> Add user responses for a form. Overwrite any existing values if previous responses are available.The
/forms
endpoints do not rely on user data, but I did require authentication. We could enforce role-based access by simply checking the user role if we want to restrict new form creation to admins, for example.The basic form scheme is enforced by the OpenAPI schema and the Marshmallow data model schema. A a form contains a title, description, and array of of field groups. Each field group contains a title, description, and array of fields. Each field contains a human-readable reference name, field properties and field validations. The field properties contain the field descriptions, the valid field choices (if applicable) and the field type. The field validations indicate whether a form value is required, and optionally specifies a max_length.
You can easily add forms and responses by interacting with the SwaggerUI.
The supported field types are listed in the API schema, and include
date, dropdown, multiple_choice, email, file_upload, group, long_text, number, short_text, yes_no
. At this point theanswer_text
is accepted as-is. We could add field-type specific validation in theupdate_responses
controller, or we can delegate this validation to the frontend.Rationale behind the changes?
These endpoints give us the basic building blocks to store and retrieve any form containing user-specific responses.
I have not added any form, but I'd be happy to update the database to include the intake form if you have one available. This can be done by seeding the database during startup, or by modifying the existing alembic script to include the form.
Testing done for these changes
Other Changes
Updated Data Model