From 9521483a035448a39b4f4a3557b371e1a2206be0 Mon Sep 17 00:00:00 2001 From: Stephen Daly Date: Fri, 20 Dec 2024 12:16:39 +0000 Subject: [PATCH] Add report to get all live forms 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. --- Gemfile | 4 ++++ Gemfile.lock | 4 ++++ app/controllers/api/v1/reports_controller.rb | 5 +++++ config/routes.rb | 1 + 4 files changed, 14 insertions(+) diff --git a/Gemfile b/Gemfile index bdfd734a..40c9205c 100644 --- a/Gemfile +++ b/Gemfile @@ -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] diff --git a/Gemfile.lock b/Gemfile.lock index 38112eb4..2f32c007 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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 @@ -350,6 +353,7 @@ DEPENDENCIES faker govuk-forms-markdown! lograge + pagy paper_trail pg (~> 1.5) puma (~> 6.5) diff --git a/app/controllers/api/v1/reports_controller.rb b/app/controllers/api/v1/reports_controller.rb index f1f4d522..01dc642d 100644 --- a/app/controllers/api/v1/reports_controller.rb +++ b/app/controllers/api/v1/reports_controller.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 381afe55..91bfe0da 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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