diff --git a/app/controllers/concerns/paginator.rb b/app/controllers/concerns/paginator.rb index 6e8305d33e52f6f21953991762ed150ff54e02bf..fa68416d0d8a1dd4133f497a78d9ac84162b2e7c 100644 --- a/app/controllers/concerns/paginator.rb +++ b/app/controllers/concerns/paginator.rb @@ -21,8 +21,9 @@ module Paginator extend ActiveSupport::Concern def paginate(model) + model = params_actions(model) total_count model - return params_actions(model.limit(limit).offset(offset)) if model.respond_to?('limit') + return model.limit(limit).offset(offset) if model.respond_to?('limit') return model[offset..limit] end @@ -52,8 +53,8 @@ module Paginator end # ordering - model = model.order("#{params[:sort]} ASC") if !params[:sort].blank? and params[:order] == 'ASC' - model = model.order("#{params[:sort]} DESC") if !params[:sort].blank? and params[:order] == 'DESC' + to_sort = JSON.parse params[:sort] if !params[:sort].blank? + model = model.order("#{to_sort[0]} #{to_sort[1]}") if !to_sort.blank? return model end diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index ebc014ece39db5de8338479767905ac500ae8c01..06ada88cbcd805788e67ff35ca1a3d9bb372c7db 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -80,7 +80,8 @@ class V1::CollectionsController < ApplicationController @collection.delete_items(items) end @collection.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end # POST /v1/collections/1/items diff --git a/app/controllers/v1/institutions_controller.rb b/app/controllers/v1/institutions_controller.rb index 06186a9c5dc116b346a33de7f536fd7cffd2e094..1d5c4739cbfc8b1da38f92f871bb2654d4352b3a 100644 --- a/app/controllers/v1/institutions_controller.rb +++ b/app/controllers/v1/institutions_controller.rb @@ -66,7 +66,8 @@ class V1::InstitutionsController < ApplicationController # DELETE v1/institutions/1.json def destroy @institution.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end def users diff --git a/app/controllers/v1/languages_controller.rb b/app/controllers/v1/languages_controller.rb index f3c4744158817fe3b841253501b272a576aa4929..ce098797e3cdc5f9f6def8dfa12cb43889f53705 100644 --- a/app/controllers/v1/languages_controller.rb +++ b/app/controllers/v1/languages_controller.rb @@ -62,7 +62,8 @@ class V1::LanguagesController < ApplicationController # DELETE /languages/1.json def destroy @language.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end private diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index ed62d375753834f4b230efb7cee71bcedc1f8736..1a9913e88f2727c3e3e25fab942b5b8d935c4fdd 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -89,7 +89,8 @@ class V1::LearningObjectsController < ApplicationController # DELETE /learning_objects/1.json def destroy @learning_object.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end # GET /v1/learning_objects/magnetlink/:magnetlink diff --git a/app/controllers/v1/mime_types_controller.rb b/app/controllers/v1/mime_types_controller.rb index d551dc4da29b3709454812d2dc2b29ccea73d732..6bd8f10f7ed4385582d15c89c019e789eba42edc 100644 --- a/app/controllers/v1/mime_types_controller.rb +++ b/app/controllers/v1/mime_types_controller.rb @@ -64,7 +64,8 @@ class V1::MimeTypesController < ApplicationController # DELETE /mime_types/1.json def destroy @mime_type.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end private diff --git a/app/controllers/v1/ratings_controller.rb b/app/controllers/v1/ratings_controller.rb index a2928122205f9c2c7ceff5df0074500156632350..33ddcfda6f79e635d7d265ab61be642eeba18927 100644 --- a/app/controllers/v1/ratings_controller.rb +++ b/app/controllers/v1/ratings_controller.rb @@ -65,7 +65,8 @@ class V1::RatingsController < ApplicationController # DELETE v1/ratings/1.json def destroy @rating.destroy - render nothing: true, status: :ok + response = { 'status': 'deleted' } + render nothing: true, status: :ok, json: response end private diff --git a/app/controllers/v1/roles_controller.rb b/app/controllers/v1/roles_controller.rb index 108103916502ca0e5bd5b48bfd1be7666b99c166..4509fbf9a92b51bc68218cc25d54e7a51a0698cf 100644 --- a/app/controllers/v1/roles_controller.rb +++ b/app/controllers/v1/roles_controller.rb @@ -64,7 +64,8 @@ class V1::RolesController < ApplicationController # DELETE /roles/1.json def destroy @role.destroy - render status: :ok + response = { 'status': 'deleted' } + render status: :ok, json: response end private diff --git a/app/controllers/v1/scores_controller.rb b/app/controllers/v1/scores_controller.rb index 2d866c3b4b0288ee2d2650f1d8d4b9e60543b166..578d2d5024feb88dde0752178c1c273763f768f2 100644 --- a/app/controllers/v1/scores_controller.rb +++ b/app/controllers/v1/scores_controller.rb @@ -26,7 +26,8 @@ class V1::ScoresController < ApplicationController # GET v1/scores # GET v1/scores.json def index - scores = paginate Score.order("name ASC").all + params[:sort] = '["name","ASC"]' if params[:sort].blank? + scores = paginate Score render json: scores end