Files
turbovault-app/app/controllers/dashboard_controller.rb
2026-03-28 19:24:29 -04:00

27 lines
1.1 KiB
Ruby

class DashboardController < ApplicationController
before_action :require_authentication
def index
@recently_added_games = current_user.games.recent.limit(5)
@currently_playing_games = current_user.games.currently_playing.limit(5)
@total_games = current_user.games.count
@physical_games = current_user.games.physical_games.count
@digital_games = current_user.games.digital_games.count
@completed_games = current_user.games.completed.count
@backlog_games = current_user.games.backlog.count
@total_spent = current_user.games.sum(:price_paid) || 0
@games_by_platform = current_user.games.joins(:platform)
.group("platforms.name")
.count
.sort_by { |_, count| -count }
.first(5)
@games_by_genre = current_user.games.joins(:genres)
.group("genres.name")
.count
.sort_by { |_, count| -count }
.first(5)
end
end