Skip to content

Commit 1e115f9

Browse files
committed
Add complete plan flag to plan_presenter
- Edit initialize to include complete flag, which is set to false as default - If flag is true in call, call fetch_all_q_and_a - Add fetch_all_q_and_a function that fetches questions and answers Update plan_presenter
1 parent bd71b23 commit 1e115f9

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

app/presenters/api/v2/plan_presenter.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Api
44
module V2
55
# Helper class for the API V2 project / DMP
66
class PlanPresenter
7-
attr_reader :data_contact, :contributors, :costs
7+
attr_reader :data_contact, :contributors, :costs, :complete_plan_data
88

9-
def initialize(plan:)
9+
def initialize(plan:, complete: false)
1010
@contributors = []
1111
return unless plan.present?
1212

@@ -22,6 +22,8 @@ def initialize(plan:)
2222
end
2323

2424
@costs = plan_costs(plan: @plan)
25+
26+
@complete_plan_data = fetch_all_q_and_a if complete
2527
end
2628

2729
# Extract the ARK or DOI for the DMP OR use its URL if none exists
@@ -55,6 +57,24 @@ def plan_costs(plan:)
5557
currency_code: 'usd', value: answer.text }
5658
end
5759
end
60+
61+
# Fetch all questions and answers from a plan, regardless of theme
62+
def fetch_all_q_and_a
63+
answers = @plan.answers.includes(question: [:section])
64+
return [] unless answers.present?
65+
66+
answers.filter_map do |answer|
67+
q = answer.question
68+
next unless q.present?
69+
70+
{
71+
title: "Question #{q.number || q.id}",
72+
section: q.section&.title,
73+
question: q.text.to_s,
74+
answer: answer.text.to_s
75+
}
76+
end
77+
end
5878
end
5979
end
6080
end

0 commit comments

Comments
 (0)