Skip to content

Commit

Permalink
Add report to get all live forms
Browse files Browse the repository at this point in the history
Add API endpoint to retrieve all live forms for the purpose of
generating reports. This uses the "api-pagination" and "pagy" gems to
paginate the results to avoid sending all the form data in one API
response.

We return all the form data for forms-admin to process so that
organisation and group data can be added to the report.
  • Loading branch information
stephencdaly committed Dec 23, 2024
1 parent 1a3c9e4 commit 9521483
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ gem "validate_url"
# For pausing pipelines
gem "aws-sdk-codepipeline", "~> 1.92"

# For pagination in the API
gem "api-pagination"
gem "pagy"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
gem "debug", platforms: %i[mri mingw x64_mingw]
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ GEM
after_commit_everywhere (1.5.0)
activerecord (>= 4.2)
activesupport
api-pagination (6.0.0)
ast (2.4.2)
aws-eventstream (1.3.0)
aws-partitions (1.1026.0)
Expand Down Expand Up @@ -182,6 +183,7 @@ GEM
nokogiri (1.17.2-x86_64-linux)
racc (~> 1.4)
ostruct (0.6.0)
pagy (9.3.3)
paper_trail (16.0.0)
activerecord (>= 6.1)
request_store (~> 1.4)
Expand Down Expand Up @@ -340,6 +342,7 @@ DEPENDENCIES
aasm (~> 5.5)
acts_as_list
after_commit_everywhere (~> 1.5)
api-pagination
aws-sdk-codepipeline (~> 1.92)
bootsnap
brakeman
Expand All @@ -350,6 +353,7 @@ DEPENDENCIES
faker
govuk-forms-markdown!
lograge
pagy
paper_trail
pg (~> 1.5)
puma (~> 6.5)
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/api/v1/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ def selection_questions_with_checkboxes

render json: data.to_json, status: :ok
end

def live_forms
live_forms = Api::V2::FormDocument.where(tag: "live")
paginate json: live_forms, per_page: 500
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
get "/selection-questions-with-autocomplete", to: "api/v1/reports#selection_questions_with_autocomplete"
get "/selection-questions-with-radios", to: "api/v1/reports#selection_questions_with_radios"
get "/selection-questions-with-checkboxes", to: "api/v1/reports#selection_questions_with_checkboxes"
get "/live-forms", to: "api/v1/reports#all_live_forms"
end
end
end

0 comments on commit 9521483

Please sign in to comment.