Skip to content

Commit

Permalink
rubocop final
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnacalindi committed Nov 16, 2024
1 parent d5017ec commit b3daf02
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ class UsersController < ApplicationController
def index
@all_roles = Role.all
@all_games = Game.where.not(id: -1).pluck(:name)

# Base query to fetch users
if params[:search].present?
search_term = params[:search].downcase
@users = User.left_joins(roles: :game)
.where("LOWER(users.first_name) LIKE :search
OR LOWER(users.last_name) LIKE :search
.where("LOWER(users.first_name) LIKE :search
OR LOWER(users.last_name) LIKE :search
OR LOWER(roles.role) LIKE :search
OR LOWER(games.name) LIKE :search", search: "%#{search_term}%")
.distinct
else
@users = User.all
end

# Collect user IDs based on filters
filtered_user_ids = Set.new

# Apply role filters if provided
if params[:roles].present?
role_user_ids = Role.where(role: params[:roles]).pluck(:user_id)
filtered_user_ids.merge(role_user_ids)
end

# Apply game filters if provided
if params[:games].present?
params[:games].each do |role, games|
Expand All @@ -37,7 +37,7 @@ def index
filtered_user_ids.merge(game_user_ids)
end
end

# Retrieve users matching the collected user IDs
if filtered_user_ids.any?
@users = User.where(id: filtered_user_ids)
Expand Down

0 comments on commit b3daf02

Please sign in to comment.