FEATURE: add parameter that allows you to filter directory items on user

adding ?username= will filter directory_items.json by the username
This commit is contained in:
Sam 2015-12-30 15:00:00 +11:00
parent 92724dcee1
commit 736cbf3d2d

View File

@ -35,6 +35,15 @@ class DirectoryItemsController < ApplicationController
end end
end end
if params[:username]
user_id = User.where(username_lower: params[:username].to_s.downcase).pluck(:id).first
if user_id
result = result.where(user_id: user_id)
else
result = result.where('false')
end
end
result = result.order('users.username') result = result.order('users.username')
result_count = result.dup.count result_count = result.dup.count
result = result.limit(PAGE_SIZE).offset(PAGE_SIZE * page).to_a result = result.limit(PAGE_SIZE).offset(PAGE_SIZE * page).to_a