Skip to content

Commit

Permalink
fast name search by default
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Oct 26, 2020
1 parent 915eb85 commit acb7233
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/controllers/api/v1/pins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ def index
@status = 'pinned' if @status.blank?
@scope = current_user.pins.not_deleted.order('created_at DESC').status(@status)

@scope = @scope.name_contains(params[:name]) if params[:name].present?
if params[:name].present?
case params[:match]
when 'iexact'
@scope = @scope.where('name ilike ?', params[:name])
when 'partial'
@scope = @scope.where('name like ?', "%#{params[:name]}%")
when 'ipartial'
@scope = @scope.where('name ilike ?', "%#{params[:name]}%")
else
@scope = @scope.where(name: params[:name])
end
end

@scope = @scope.cids(params[:cid].split(',').first(10)) if params[:cid].present?
@scope = @scope.before(params[:before]) if params[:before].present?
@scope = @scope.after(params[:after]) if params[:after].present?
Expand Down

0 comments on commit acb7233

Please sign in to comment.