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

Spike add multiple answers #509

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ gem "validate_url"
# For pausing pipelines
gem "aws-sdk-codepipeline", "~> 1.74"

gem "active_model_serializers"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for proof of concept but we shouldn't use this gem as it's not fully released (and has gone into maintenance mode) https://github.com/rails-api/active_model_serializers?tab=readme-ov-file#alternatives

I think we should be able to do something like:

JSON.generate(Form.includes(:question_steps).where("form.id = ?", 1).to_h)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh good point about the gem. I was just scouring the internet for something that we could use to spit out the JSON in the desired format, I'm sure we can find a way without using this particular gem.


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
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ GEM
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
active_model_serializers (0.10.14)
actionpack (>= 4.1)
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (7.1.3.4)
activesupport (= 7.1.3.4)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -114,6 +119,8 @@ GEM
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
case_transform (0.2)
activesupport
concurrent-ruby (1.3.1)
config (5.5.1)
deep_merge (~> 1.2, >= 1.2.1)
Expand Down Expand Up @@ -145,6 +152,7 @@ GEM
reline (>= 0.4.2)
jmespath (1.6.2)
json (2.7.2)
jsonapi-renderer (0.2.2)
language_server-protocol (3.17.0.3)
lograge (0.14.0)
actionpack (>= 4)
Expand Down Expand Up @@ -344,6 +352,7 @@ PLATFORMS

DEPENDENCIES
aasm (~> 5.5)
active_model_serializers
acts_as_list
after_commit_everywhere (~> 1.4)
aws-sdk-codepipeline (~> 1.74)
Expand Down
5 changes: 5 additions & 0 deletions app/serializers/form_snapshot_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FormSnapshotSerializer < ActiveModel::Serializer
attributes :id, :name, :submission_email, :privacy_policy_url, :form_slug, :support_email, :support_phone, :support_url, :support_url_text, :declaration_text, :what_happens_next_markdown, :payment_url

has_many :steps
end
3 changes: 3 additions & 0 deletions app/serializers/question_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class QuestionSerializer < ActiveModel::Serializer
attributes :question_text
end
5 changes: 5 additions & 0 deletions app/serializers/question_set_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class QuestionSetSerializer < ActiveModel::Serializer
attributes :name

has_many :steps
end
6 changes: 6 additions & 0 deletions app/serializers/step_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class StepSerializer < ActiveModel::Serializer
attributes :id, :next_step_id, :position
attribute :positionable_type, key: :type

has_one :positionable, key: :data
end