Skip to content

Commit edb167a

Browse files
committed
fix: adjust into to model 4 show custom order
1. Adicionado scope ordered_by_role no model Player (app/models/player.rb:41-52) - Usa CASE WHEN do SQL para ordenar na sequência correta: top → jungle → mid → adc → support 2. Atualizado PlayersController (app/controllers/api/v1/players_controller.rb:18) - Substituiu .order(:role, :summoner_name) por .ordered_by_role.order(:summoner_name) - Agora ordena primeiro por posição (na ordem correta) e depois pelo nome do jogador 3. Atualizado DashboardController (app/controllers/api/v1/dashboard_controller.rb:113) - O by_role agora também respeita a ordem correta das posições
1 parent 8892c96 commit edb167a

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

app/controllers/api/v1/dashboard_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ def active_goals_data
109109
def roster_status_data
110110
players = organization_scoped(Player).includes(:champion_pools)
111111

112+
# Order by role to ensure consistent order in by_role hash
113+
by_role_ordered = players.ordered_by_role.group(:role).count
114+
112115
{
113-
by_role: players.group(:role).count,
116+
by_role: by_role_ordered,
114117
by_status: players.group(:status).count,
115118
contracts_expiring: players.contracts_expiring_soon.count
116119
}

app/controllers/api/v1/players_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def index
1414
players = players.where('summoner_name ILIKE ? OR real_name ILIKE ?', search_term, search_term)
1515
end
1616

17-
# Pagination
18-
result = paginate(players.order(:role, :summoner_name))
17+
# Pagination - order by role (top, jungle, mid, adc, support) then by name
18+
result = paginate(players.ordered_by_role.order(:summoner_name))
1919

2020
render_success({
2121
players: PlayerSerializer.render_as_hash(result[:data]),

app/models/player.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ class Player < ApplicationRecord
3838
where(contract_end_date: Date.current..Date.current + days.days)
3939
}
4040
scope :by_tier, ->(tier) { where(solo_queue_tier: tier) }
41+
scope :ordered_by_role, -> {
42+
order(Arel.sql(
43+
"CASE role
44+
WHEN 'top' THEN 1
45+
WHEN 'jungle' THEN 2
46+
WHEN 'mid' THEN 3
47+
WHEN 'adc' THEN 4
48+
WHEN 'support' THEN 5
49+
ELSE 6
50+
END"
51+
))
52+
}
4153

4254
# Instance methods
4355
def current_rank_display

0 commit comments

Comments
 (0)