Commit 6af34b0f authored by Stephan van Leeuwen's avatar Stephan van Leeuwen

Changed setting the sort variable

Changed from using cases to set the sort variable, to use a one line if/else statement
parent 6b507219
...@@ -22,11 +22,7 @@ module API ...@@ -22,11 +22,7 @@ module API
# GET /projects # GET /projects
get do get do
@projects = current_user.authorized_projects @projects = current_user.authorized_projects
sort = params[:sort] == 'desc' ? 'desc' : 'asc'
sort = case params["sort"]
when 'desc' then 'DESC'
else 'ASC'
end
@projects = case params["order_by"] @projects = case params["order_by"]
when 'id' then @projects.reorder("id #{sort}") when 'id' then @projects.reorder("id #{sort}")
...@@ -50,11 +46,7 @@ module API ...@@ -50,11 +46,7 @@ module API
# Example Request: # Example Request:
# GET /projects/owned # GET /projects/owned
get '/owned' do get '/owned' do
sort = case params["sort"] sort = params[:sort] == 'desc' ? 'desc' : 'asc'
when 'desc' then 'DESC'
else 'ASC'
end
@projects = current_user.owned_projects @projects = current_user.owned_projects
@projects = case params["order_by"] @projects = case params["order_by"]
when 'id' then @projects.reorder("id #{sort}") when 'id' then @projects.reorder("id #{sort}")
...@@ -74,11 +66,7 @@ module API ...@@ -74,11 +66,7 @@ module API
# GET /projects/all # GET /projects/all
get '/all' do get '/all' do
authenticated_as_admin! authenticated_as_admin!
sort = params[:sort] == 'desc' ? 'desc' : 'asc'
sort = case params["sort"]
when 'desc' then 'DESC'
else 'ASC'
end
@projects = case params["order_by"] @projects = case params["order_by"]
when 'id' then Project.order("id #{sort}") when 'id' then Project.order("id #{sort}")
...@@ -268,11 +256,7 @@ module API ...@@ -268,11 +256,7 @@ module API
ids = current_user.authorized_projects.map(&:id) ids = current_user.authorized_projects.map(&:id)
visibility_levels = [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ] visibility_levels = [ Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC ]
projects = Project.where("(id in (?) OR visibility_level in (?)) AND (name LIKE (?))", ids, visibility_levels, "%#{params[:query]}%") projects = Project.where("(id in (?) OR visibility_level in (?)) AND (name LIKE (?))", ids, visibility_levels, "%#{params[:query]}%")
sort = params[:sort] == 'desc' ? 'desc' : 'asc'
sort = case params["sort"]
when 'desc' then 'DESC'
else 'ASC'
end
projects = case params["order_by"] projects = case params["order_by"]
when 'id' then projects.order("id #{sort}") when 'id' then projects.order("id #{sort}")
......
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