Commit 18f9640a authored by James Lopez's avatar James Lopez

refactor filters

parent 23f799d0
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
# iids: integer[] # iids: integer[]
# #
class IssuableFinder class IssuableFinder
include Gitlab::Database::CreatedAtFilter
NONE = '0'.freeze NONE = '0'.freeze
IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze IRRELEVANT_PARAMS_FOR_CACHE_KEY = %i[utf8 sort page].freeze
...@@ -438,18 +440,6 @@ class IssuableFinder ...@@ -438,18 +440,6 @@ class IssuableFinder
params[:non_archived].present? ? items.non_archived : items params[:non_archived].present? ? items.non_archived : items
end 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? def current_user_related?
params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me' params[:scope] == 'created-by-me' || params[:scope] == 'authored' || params[:scope] == 'assigned-to-me'
end end
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# skip_ldap: boolean # skip_ldap: boolean
# #
class UsersFinder class UsersFinder
include Gitlab::Database::CreatedAtFilter
attr_accessor :current_user, :params attr_accessor :current_user, :params
def initialize(current_user, params = {}) def initialize(current_user, params = {})
......
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 ...@@ -164,7 +164,7 @@ describe API::Users do
expect(response).to have_http_status(400) expect(response).to have_http_status(400)
end 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)) user = create(:user, created_at: Date.new(2000,1,1))
get api("/users?created_before=2000-01-02T00:00:00.060Z", admin) 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