129 lines
3.8 KiB
Ruby
129 lines
3.8 KiB
Ruby
# Promoter Events Controller
|
|
#
|
|
# Handles event management for promoters (event organizers)
|
|
# Allows promoters to create, edit, delete and manage their events
|
|
class Promoter::EventsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :ensure_can_manage_events!
|
|
before_action :set_event, only: [ :show, :edit, :update, :destroy, :publish, :unpublish, :cancel, :mark_sold_out, :duplicate ]
|
|
|
|
# Display all events for the current promoter
|
|
def index
|
|
@events = current_user.events.order(created_at: :desc).page(params[:page]).per(10)
|
|
end
|
|
|
|
# Display a specific event for the promoter
|
|
def show
|
|
# Event is set by set_event callback
|
|
end
|
|
|
|
# Show form to create a new event
|
|
def new
|
|
@event = current_user.events.build
|
|
end
|
|
|
|
# Create a new event
|
|
def create
|
|
@event = current_user.events.build(event_params)
|
|
|
|
if @event.save
|
|
redirect_to promoter_event_path(@event), notice: "Event créé avec succès!"
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
# Show form to edit an existing event
|
|
def edit
|
|
# Event is set by set_event callback
|
|
end
|
|
|
|
# Update an existing event
|
|
def update
|
|
if @event.update(event_params)
|
|
redirect_to promoter_event_path(@event), notice: "Event mis à jour avec succès!"
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
# Delete an event
|
|
def destroy
|
|
@event.destroy
|
|
redirect_to promoter_events_path, notice: "Event supprimé avec succès!"
|
|
end
|
|
|
|
# Publish an event (make it visible to public)
|
|
def publish
|
|
if @event.draft?
|
|
@event.update(state: :published)
|
|
redirect_to promoter_event_path(@event), notice: "Event publié avec succès!"
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: "Cet event ne peut pas être publié."
|
|
end
|
|
end
|
|
|
|
# Unpublish an event (make it draft)
|
|
def unpublish
|
|
if @event.published?
|
|
@event.update(state: :draft)
|
|
redirect_to promoter_event_path(@event), notice: "Event dépublié avec succès!"
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: "Cet event ne peut pas être dépublié."
|
|
end
|
|
end
|
|
|
|
# Cancel an event
|
|
def cancel
|
|
if @event.published?
|
|
@event.update(state: :canceled)
|
|
redirect_to promoter_event_path(@event), notice: "Event annulé avec succès!"
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: "Cet event ne peut pas être annulé."
|
|
end
|
|
end
|
|
|
|
# Mark event as sold out
|
|
def mark_sold_out
|
|
if @event.published?
|
|
@event.update(state: :sold_out)
|
|
redirect_to promoter_event_path(@event), notice: "Event marqué comme complet!"
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: "Cet event ne peut pas être marqué comme complet."
|
|
end
|
|
end
|
|
|
|
# Duplicate an event and all its ticket types
|
|
def duplicate
|
|
@new_event = @event.duplicate
|
|
|
|
if @new_event
|
|
redirect_to edit_promoter_event_path(@new_event), notice: "Événement dupliqué avec succès! Vous pouvez maintenant modifier les détails de l'événement copié."
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: "Erreur lors de la duplication de l'événement."
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_can_manage_events!
|
|
unless current_user.can_manage_events?
|
|
redirect_to dashboard_path, alert: "Vous n'avez pas les permissions nécessaires pour gérer des événements."
|
|
end
|
|
end
|
|
|
|
def set_event
|
|
@event = current_user.events.find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
redirect_to promoter_events_path, alert: "Event non trouvé ou vous n'avez pas accès à cet event."
|
|
end
|
|
|
|
def event_params
|
|
params.require(:event).permit(
|
|
:name, :slug, :description, :image,
|
|
:venue_name, :venue_address, :latitude, :longitude,
|
|
:start_time, :end_time, :featured, :allow_booking_during_event
|
|
)
|
|
end
|
|
end
|