# Controller for static pages and user dashboard # Handles basic page rendering and user-specific content class PagesController < ApplicationController before_action :authenticate_user!, only: [ :dashboard ] # Homepage showing featured events # # Display homepage with featured events and incoming ones def home @featured_events = Event.published.featured.limit(3) if user_signed_in? redirect_to(dashboard_path) end end # User dashboard showing personalized content # Accessible only to authenticated users def dashboard # Metrics for dashboard cards @booked_events = current_user.orders.joins(tickets: { ticket_type: :event }) .where(events: { state: :published }) .where(orders: { status: [ "paid", "completed" ] }) .sum("1") @events_today = Event.published.where("DATE(start_time) = ?", Date.current).count @events_tomorrow = Event.published.where("DATE(start_time) = ?", Date.current + 1).count @upcoming_events = Event.published.upcoming.count # User's booked events @user_booked_events = Event.joins(ticket_types: { tickets: :order }) .where(orders: { user: current_user }, tickets: { status: "active" }) .distinct .limit(5) # Draft orders that can be retried @draft_orders = current_user.orders.includes(tickets: [ :ticket_type, :event ]) .can_retry_payment .order(:expires_at) # Events sections @today_events = Event.published.where("DATE(start_time) = ?", Date.current).order(start_time: :asc) @tomorrow_events = Event.published.where("DATE(start_time) = ?", Date.current + 1).order(start_time: :asc) @other_events = Event.published.upcoming.where.not("DATE(start_time) IN (?)", [ Date.current, Date.current + 1 ]).order(start_time: :asc).page(params[:page]) end # Events page showing all published events with pagination def events @events = Event.published.order(created_at: :desc).page(params[:page]) end end