diff --git a/app/controllers/api/v0/dmptemplates_controller.rb b/app/controllers/api/v0/dmptemplates_controller.rb new file mode 100644 index 0000000..6680342 --- /dev/null +++ b/app/controllers/api/v0/dmptemplates_controller.rb @@ -0,0 +1,21 @@ +module Api + module V0 + class DmptemplatesController < Api::V0::BaseController + before_action :authenticate + + swagger_controller :dmptemplates, 'Templates' + + def index + # check if the user has permissions to use the templates API + if has_auth("templates") + @all_templates = Dmptemplate.all + respond_with @all_templates + else + #render unauthorised + render json: I18n.t("api.no_auth_for_endpoint"), status: 401 + end + + end + end + end +end \ No newline at end of file diff --git a/app/views/api/v0/dmptemplates/index.json.jbuilder b/app/views/api/v0/dmptemplates/index.json.jbuilder new file mode 100644 index 0000000..33ebd74 --- /dev/null +++ b/app/views/api/v0/dmptemplates/index.json.jbuilder @@ -0,0 +1,14 @@ +# builds a json response to api query for a list of all dmptemplates +json.prettify! + +json.templates Organisation.all.each do |org| + unless org.published_templates.blank? + json.organisation_name org.name + json.organisation_id org.id + json.organisation_templates org.published_templates.each do |template| + json.title template.title + json.id template.id + json.description template.description + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 6d342ee..ac744dc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -176,8 +176,8 @@ namespace :api, defaults: {format: :json} do namespace :v0 do resources :guidance_groups, only: [:index, :show] - resources :guidances, only: [:index, :show] resources :plans, only: :create, controller: "projects", path: "plans" + resources :templates, only: :index, controller: "dmptemplates", path: "templates" end end