filter maps by user_id in api
This commit is contained in:
parent
6cc827d11c
commit
0530c9182a
3 changed files with 17 additions and 0 deletions
|
@ -5,6 +5,11 @@ module Api
|
||||||
def searchable_columns
|
def searchable_columns
|
||||||
[:name, :desc]
|
[:name, :desc]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply_filters(collection)
|
||||||
|
collection = collection.where(user_id: params[:user_id]) if params[:user_id]
|
||||||
|
collection
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -141,6 +141,7 @@ module Api
|
||||||
collection = accessible_records
|
collection = accessible_records
|
||||||
collection = yield collection if block_given?
|
collection = yield collection if block_given?
|
||||||
collection = search_by_q(collection) if params[:q]
|
collection = search_by_q(collection) if params[:q]
|
||||||
|
collection = apply_filters(collection)
|
||||||
collection = order_by_sort(collection) if params[:sort]
|
collection = order_by_sort(collection) if params[:sort]
|
||||||
collection = collection.page(params[:page]).per(params[:per])
|
collection = collection.page(params[:page]).per(params[:per])
|
||||||
self.collection = collection
|
self.collection = collection
|
||||||
|
@ -167,6 +168,11 @@ module Api
|
||||||
collection.where(condition)
|
collection.where(condition)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def apply_filters(collection)
|
||||||
|
# override this function for specific filters
|
||||||
|
collection
|
||||||
|
end
|
||||||
|
|
||||||
def order_by_sort(collection)
|
def order_by_sort(collection)
|
||||||
builder = collection
|
builder = collection
|
||||||
sorts = params[:sort].split(',')
|
sorts = params[:sort].split(',')
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
get:
|
get:
|
||||||
is: [ searchable: { searchFields: "name, desc" }, embeddable: { embedFields: "user,topics,synapses,mappings,contributors,collaborators" }, orderable, pageable ]
|
is: [ searchable: { searchFields: "name, desc" }, embeddable: { embedFields: "user,topics,synapses,mappings,contributors,collaborators" }, orderable, pageable ]
|
||||||
securedBy: [ null, token, oauth_2_0, cookie ]
|
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:
|
responses:
|
||||||
200:
|
200:
|
||||||
body:
|
body:
|
||||||
|
|
Loading…
Add table
Reference in a new issue