-
Notifications
You must be signed in to change notification settings - Fork 118
[DRAFT] Add question and answer flag to V2 API #3590
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
base: api_v2_dmponline
Are you sure you want to change the base?
Conversation
- This optional parameter is added to the plans endpoints in the V2 API
- This function fetches all questions and answers belonging to a plan.
Generated by 🚫 Danger |
| if @question_and_answer | ||
| json.questions_and_answers do | ||
| outputs.each do |output| | ||
| presenter = Api::V2::ResearchOutputPresenter.new(output: output) | ||
| q_and_a = presenter.send(:fetch_all_q_and_a, plan: plan) | ||
| next if q_and_a.blank? | ||
|
|
||
| json.set! output.id.to_s do | ||
| json.array! q_and_a do |item| | ||
| json.title item[:title] | ||
| json.question item[:question] | ||
| json.answer item[:answer] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking at the comment at the top of this file:
# Note the symbol of the dmproadmap json object
# nested in extensions which is the container for the json template object, etc.
# A JSON representation of a Data Management Plan in the
# RDA Common Standard format
With the exception of json.extension, I think all of the keys here map onto the RDA-DMP-Common-Standard structure. Maybe this additional data should also be placed inside of json.extension?
| if @question_and_answer | ||
| json.questions_and_answers do | ||
| outputs.each do |output| | ||
| presenter = Api::V2::ResearchOutputPresenter.new(output: output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you did this because app/presenters/api/v2/research_output_presenter.rb already has some other q_and_a methods, but I'm not sure about this approach.
It looks like Api::V2::ResearchOutputPresenter is currently only instantiated in app/views/api/v2/datasets/_show.json.jbuilder, which is responsible for the dataset section of the RDA DMP Common Standard structure. Because fetch_all_q_and_a(plan:) isn't being used for that section, I don't think we should define it there.
I worry about directly calling the private fetch_all_q_and_a method from here as well.
Since this view is already instantiating Api::V2::PlanPresenter, maybe defining fetch_all_q_and_a there might better fit the existing architecture?
Changes proposed in this PR:
question_and_answerflag to the V2 API to enable accessing all questions and answers belonging to a plan in the API response.defaults to false and thereby is compliant with the RDA metadata standard, but can be
passed in with a value of true to include the questions and answers of the plan."
api/v2/plansandapi/v2/plans/[plan_id]endpoints. For example:api/v2/plans/12345?question_and_answer=true.api/v2/plans/15476?question_and_answer=trueresponse.json