Skip to content
Snippets Groups Projects
Commit ef31bb22 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

routes to add and remove educational_stages separately

parent 2963a8dc
No related branches found
No related tags found
No related merge requests found
module StageableController
extend ActiveSupport::Concern
included do
before_action :authenticate_user!, only: [:add_stages, :remove_stages]
end
# POST /v1/learning_objects/1/educational_stages
# POST /v1/learning_objects/1/educational_stages.json
def add_stages
stageable.add_educational_stages(ids: params[:educational_stages])
render json: stageable.educational_stages, status: :created
end
# DELETE /v1/learning_objects/1/educational_stages
# DELETE /v1/learning_objects/1/educational_stages.json
def remove_stages
stageable.remove_educational_stages(ids: params[:educational_stages])
render json: stageable.educational_stages, status: :ok
end
protected
def stageable
raise NotImplementedError
end
end
...@@ -7,11 +7,12 @@ class V1::LearningObjectsController < ApplicationController ...@@ -7,11 +7,12 @@ class V1::LearningObjectsController < ApplicationController
include ::DeletedObjectsController include ::DeletedObjectsController
include ::HighlightsController include ::HighlightsController
include ::SubjectableController include ::SubjectableController
include ::StageableController
before_action :authenticate_user!, except: [:create, :index, :show] before_action :authenticate_user!, except: [:create, :index, :show]
before_action :set_learning_object, only: [:show, :update, :destroy] before_action :set_learning_object, only: [:show, :update, :destroy]
before_action :set_new_learning_object, only: :index before_action :set_new_learning_object, only: :index
before_action :authorize!, except: [:create, :tagging, :untagging, :subjecting, :unsubjecting] before_action :authorize!, except: [:create, :tagging, :untagging, :subjecting, :unsubjecting, :add_stages, :remove_stages]
def index def index
learning_objects = paginate LearningObject.includes(:tags, :publisher, :language, :license, :subjects, :educational_stages, :reviews) learning_objects = paginate LearningObject.includes(:tags, :publisher, :language, :license, :subjects, :educational_stages, :reviews)
...@@ -71,6 +72,7 @@ class V1::LearningObjectsController < ApplicationController ...@@ -71,6 +72,7 @@ class V1::LearningObjectsController < ApplicationController
def sociable; set_learning_object; end def sociable; set_learning_object; end
def taggable; set_learning_object; end def taggable; set_learning_object; end
def subjectable; set_learning_object; end def subjectable; set_learning_object; end
def stageable; set_learning_object; end
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_learning_object def set_learning_object
......
...@@ -29,6 +29,13 @@ Rails.application.routes.draw do ...@@ -29,6 +29,13 @@ Rails.application.routes.draw do
end end
end end
concern :stageable do
member do
post 'educational_stages', as: :add_stages, action: :add_stages
delete 'educational_stages', as: :remove_stages, action: :remove_stages
end
end
concern :sociable do concern :sociable do
member do member do
post 'like', as: :like, action: :like post 'like', as: :like, action: :like
...@@ -102,14 +109,14 @@ Rails.application.routes.draw do ...@@ -102,14 +109,14 @@ Rails.application.routes.draw do
end end
end end
resources :collections, concerns: [:followable, :sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable] do resources :collections, concerns: [:followable, :sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable] do
member do member do
post :items, to: 'collections#add_object' post :items, to: 'collections#add_object'
delete :items, to: 'collections#delete_object' delete :items, to: 'collections#delete_object'
end end
end end
resources :learning_objects, concerns: [:sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable] do resources :learning_objects, concerns: [:sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable] do
member do member do
resource :chunk, module: 'learning_objects', only: [:create, :show] resource :chunk, module: 'learning_objects', only: [:create, :show]
resource :upload, module: 'learning_objects', only: :create resource :upload, module: 'learning_objects', only: :create
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment