Skip to content

Commit

Permalink
Merge pull request #5 from ipfs-shipyard/fast-name-search
Browse files Browse the repository at this point in the history
fast name search by default
  • Loading branch information
andrew authored Oct 27, 2020
2 parents 55df82b + 1a022dd commit b5ca346
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 b5ca346

Please sign in to comment.