add filtering/sorting params to collection characters endpoint
This commit is contained in:
parent
689aa96645
commit
4a471dd273
2 changed files with 9 additions and 0 deletions
|
|
@ -21,6 +21,9 @@ module Api
|
|||
@collection_characters = @collection_characters.by_proficiency(params[:proficiency]) if params[:proficiency]
|
||||
@collection_characters = @collection_characters.by_gender(params[:gender]) if params[:gender]
|
||||
|
||||
# Apply sorting
|
||||
@collection_characters = @collection_characters.sorted_by(params[:sort])
|
||||
|
||||
# Apply pagination
|
||||
@collection_characters = @collection_characters.paginate(page: params[:page], per_page: params[:limit] || 50)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ module Api
|
|||
def characters
|
||||
filters = search_params[:filters]
|
||||
locale = search_params[:locale] || 'en'
|
||||
exclude = search_params[:exclude]
|
||||
conditions = {}
|
||||
|
||||
if filters
|
||||
|
|
@ -88,6 +89,11 @@ module Api
|
|||
characters = characters.where('series && ARRAY[?]::integer[]', series_values)
|
||||
end
|
||||
|
||||
# Exclude already-owned characters (for collection modal)
|
||||
if exclude.present? && exclude.any?
|
||||
characters = characters.where.not(id: exclude)
|
||||
end
|
||||
|
||||
count = characters.length
|
||||
paginated = characters.paginate(page: search_params[:page], per_page: search_page_size)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue