diff --git a/app/controllers/api/v2/maps_controller.rb b/app/controllers/api/v2/maps_controller.rb index 0bcd9bee..e8aa3f05 100644 --- a/app/controllers/api/v2/maps_controller.rb +++ b/app/controllers/api/v2/maps_controller.rb @@ -5,6 +5,11 @@ module Api def searchable_columns [:name, :desc] end + + def apply_filters(collection) + collection = collection.where(user_id: params[:user_id]) if params[:user_id] + collection + end end end end diff --git a/app/controllers/api/v2/restful_controller.rb b/app/controllers/api/v2/restful_controller.rb index 00325ba4..08177ad7 100644 --- a/app/controllers/api/v2/restful_controller.rb +++ b/app/controllers/api/v2/restful_controller.rb @@ -141,6 +141,7 @@ module Api collection = accessible_records collection = yield collection if block_given? collection = search_by_q(collection) if params[:q] + collection = apply_filters(collection) collection = order_by_sort(collection) if params[:sort] collection = collection.page(params[:page]).per(params[:per]) self.collection = collection @@ -167,6 +168,11 @@ module Api collection.where(condition) end + def apply_filters(collection) + # override this function for specific filters + collection + end + def order_by_sort(collection) builder = collection sorts = params[:sort].split(',') diff --git a/doc/api/apis/maps.raml b/doc/api/apis/maps.raml index 03c4db2b..ad1666dd 100644 --- a/doc/api/apis/maps.raml +++ b/doc/api/apis/maps.raml @@ -2,6 +2,12 @@ get: is: [ searchable: { searchFields: "name, desc" }, embeddable: { embedFields: "user,topics,synapses,mappings,contributors,collaborators" }, orderable, pageable ] securedBy: [ null, token, oauth_2_0, cookie ] + queryParameters: + user_id: + description: | + Pass a user_id to only return maps created by that user. For example, `/api/v2/maps?user_id=1` would return maps created by the Metamaps user with id 1. + required: false + type: number responses: 200: body: