Move query notes by user value to mixin
This commit is contained in:
parent
500c1bddf2
commit
bd278a07fe
3 changed files with 37 additions and 13 deletions
|
@ -256,19 +256,8 @@ module Api
|
|||
@notes = bbox_condition(@notes)
|
||||
|
||||
# Add any user filter
|
||||
if params[:display_name] || params[:user]
|
||||
if params[:display_name]
|
||||
@user = User.find_by(:display_name => params[:display_name])
|
||||
|
||||
raise OSM::APIBadUserInput, "User #{params[:display_name]} not known" unless @user
|
||||
else
|
||||
@user = User.find_by(:id => params[:user])
|
||||
|
||||
raise OSM::APIBadUserInput, "User #{params[:user]} not known" unless @user
|
||||
end
|
||||
|
||||
@notes = @notes.joins(:comments).where(:note_comments => { :author_id => @user })
|
||||
end
|
||||
user = query_conditions_user_value
|
||||
@notes = @notes.joins(:comments).where(:note_comments => { :author_id => user }) if user
|
||||
|
||||
# Add any text filter
|
||||
if params[:q]
|
||||
|
|
|
@ -3,6 +3,33 @@ module QueryMethods
|
|||
|
||||
private
|
||||
|
||||
##
|
||||
# Filter the resulting items by user
|
||||
def query_conditions_user(items, filter_property)
|
||||
user = query_conditions_user_value
|
||||
items = items.where(filter_property => user) if user
|
||||
items
|
||||
end
|
||||
|
||||
##
|
||||
# Get user value for query filtering by user
|
||||
# Raises OSM::APIBadUserInput if user not found like notes api does, changesets api raises OSM::APINotFoundError instead
|
||||
def query_conditions_user_value
|
||||
if params[:display_name] || params[:user]
|
||||
if params[:display_name]
|
||||
user = User.find_by(:display_name => params[:display_name])
|
||||
|
||||
raise OSM::APIBadUserInput, "User #{params[:display_name]} not known" unless user
|
||||
else
|
||||
user = User.find_by(:id => params[:user])
|
||||
|
||||
raise OSM::APIBadUserInput, "User #{params[:user]} not known" unless user
|
||||
end
|
||||
|
||||
user
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Restrict the resulting items to those created during a particular time period
|
||||
# Using 'to' requires specifying 'from' as well for historical reasons
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue