Commit 377244dd authored by James Lopez's avatar James Lopez

refactor filters

parent bfe5f2d1
......@@ -19,6 +19,8 @@
# iids: integer[]
#
class IssuableFinder
include Gitlab::Database::CreatedAtFilter
NONE = '0'.freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
......@@ -408,18 +410,6 @@ class IssuableFinder
params[:non_archived].present? ? items.non_archived : items
end
def by_created_at(items)
if params[:created_after].present?
items = items.where(items.klass.arel_table[:created_at].gteq(params[:created_after]))
end
if params[:created_before].present?
items = items.where(items.klass.arel_table[:created_at].lteq(params[:created_before]))
end
items
end
def current_user_related?
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
end
......
......@@ -14,6 +14,8 @@
# external: boolean
#
class UsersFinder
include Gitlab::Database::CreatedAtFilter
attr_accessor :current_user, :params
def initialize(current_user, params = {})
......@@ -72,16 +74,4 @@ class UsersFinder
users.external
end
def by_created_at(users)
if params[:created_after].present?
users = users.where(users.klass.arel_table[:created_at].gteq(params[:created_after]))
end
if params[:created_before].present?
users = users.where(users.klass.arel_table[:created_at].lteq(params[:created_before]))
end
users
end
end
module Gitlab
module Database
module CreatedAtFilter
def by_created_at(items)
if params[:created_after].present?
items = items.where(items.klass.arel_table[:created_at].gteq(params[:created_after]))
end
if params[:created_before].present?
items = items.where(items.klass.arel_table[:created_at].lteq(params[:created_before]))
end
items
end
end
end
end
......@@ -164,7 +164,7 @@ describe API::Users do
expect(response).to have_http_status(400)
end
it "returns an user created before a specific date" do
it "returns a user created before a specific date" do
user = create(:user, created_at: Date.new(2000,1,1))
get api("/users?created_before=2000-01-02T00:00:00.060Z", admin)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment