Files
aperonight/app/models/event.rb
Kevin BATAILLE 30f3ecc6ad refactor(events): replace parties concept with events throughout the application
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

This commit refactors the entire application to replace the 'parties' concept with 'events'. All controllers, models, views, and related files have been updated to reflect this change. The parties table has been replaced with an events table, and all related functionality has been updated accordingly.
2025-08-28 13:20:51 +02:00

52 lines
2.0 KiB
Ruby
Executable File

# Event model representing nightlife events and events
# Manages event details, location data, and publication state
class Event < ApplicationRecord
# Define states for Event lifecycle management
# draft: Initial state when Event is being created
# published: Event is visible to public and can be discovered
# canceled: Event has been canceled by organizer
# sold_out: Event has reached capacity and tickets are no longer available
enum :state, {
draft: 0,
published: 1,
canceled: 2,
sold_out: 3
}, default: :draft
# === Relations ===
belongs_to :user
has_many :ticket_types, dependent: :destroy
has_many :tickets, through: :ticket_types
# Validations for Event attributes
# Basic information
validates :name, presence: true, length: { minimum: 3, maximum: 100 }
validates :slug, presence: true, length: { minimum: 3, maximum: 100 }
validates :description, presence: true, length: { minimum: 10, maximum: 1000 }
validates :state, presence: true, inclusion: { in: states.keys }
validates :image, length: { maximum: 500 } # URL or path to image
# Venue information
validates :venue_name, presence: true, length: { maximum: 100 }
validates :venue_address, presence: true, length: { maximum: 200 }
# Geographic coordinates for map display
validates :latitude, presence: true, numericality: {
greater_than_or_equal_to: -90,
less_than_or_equal_to: 90
}
validates :longitude, presence: true, numericality: {
greater_than_or_equal_to: -180,
less_than_or_equal_to: 180
}
# Scopes for querying events with common filters
scope :featured, -> { where(featured: true) } # Get featured events for homepage
scope :published, -> { where(state: :published) } # Get publicly visible events
scope :search_by_name, ->(query) { where("name ILIKE ?", "%#{query}%") } # Search by name (case-insensitive)
# Scope for published events ordered by start time
scope :upcoming, -> { published.where("start_time >= ?", Time.current).order(start_time: :asc) }
end