develop #3

Merged
kbe merged 227 commits from develop into main 2025-09-16 14:35:23 +00:00
5 changed files with 56 additions and 48 deletions
Showing only changes of commit b493027c86 - Show all commits

View File

@@ -4,8 +4,11 @@
module Api module Api
module V1 module V1
class EventsController < ApiController class EventsController < ApiController
# Skip API key authentication for store_cart action (used by frontend forms)
skip_before_action :authenticate_api_key, only: [:store_cart]
# Charge l'évén avant certaines actions pour réduire les duplications # Charge l'évén avant certaines actions pour réduire les duplications
before_action :set_event, only: [ :show, :update, :destroy ] before_action :set_event, only: [ :show, :update, :destroy, :store_cart ]
# GET /api/v1/events # GET /api/v1/events
# Récupère tous les événements triés par date de création (du plus récent au plus ancien) # Récupère tous les événements triés par date de création (du plus récent au plus ancien)
@@ -54,6 +57,18 @@ module Api
head :no_content head :no_content
end end
# POST /api/v1/events/:id/store_cart
# Store cart data in session (AJAX endpoint)
def store_cart
cart_data = params[:cart] || {}
session[:pending_cart] = cart_data
render json: { status: "success", message: "Cart stored successfully" }
rescue => e
Rails.logger.error "Error storing cart: #{e.message}"
render json: { status: "error", message: "Failed to store cart" }, status: 500
end
private private
# Trouve un événement par son ID ou retourne 404 Introuvable # Trouve un événement par son ID ou retourne 404 Introuvable

View File

@@ -6,7 +6,7 @@ class EventsController < ApplicationController
include StripeConcern include StripeConcern
before_action :authenticate_user!, only: [ :checkout, :process_names, :payment_success, :download_ticket ] before_action :authenticate_user!, only: [ :checkout, :process_names, :payment_success, :download_ticket ]
before_action :set_event, only: [ :show, :checkout, :process_names, :store_cart ] before_action :set_event, only: [ :show, :checkout, :process_names ]
# Display all events # Display all events
def index def index
@@ -91,16 +91,6 @@ class EventsController < ApplicationController
process_payment(cart_data) process_payment(cart_data)
end end
# Store cart data in session (AJAX endpoint)
def store_cart
cart_data = params[:cart] || {}
session[:pending_cart] = cart_data
render json: { status: "success", message: "Cart stored successfully" }
rescue => e
Rails.logger.error "Error storing cart: #{e.message}"
render json: { status: "error", message: "Failed to store cart" }, status: 500
end
# Handle successful payment # Handle successful payment
def payment_success def payment_success

View File

@@ -10,7 +10,7 @@ class PagesController < ApplicationController
@events = Event.published.featured.limit(3) @events = Event.published.featured.limit(3)
if user_signed_in? if user_signed_in?
return redirect_to(dashboard_path) redirect_to(dashboard_path)
end end
end end
@@ -25,14 +25,14 @@ class PagesController < ApplicationController
# User's booked events # User's booked events
@user_booked_events = Event.joins(ticket_types: :tickets) @user_booked_events = Event.joins(ticket_types: :tickets)
.where(tickets: { user: current_user, status: 'active' }) .where(tickets: { user: current_user, status: "active" })
.distinct .distinct
.limit(5) .limit(5)
# Events sections # Events sections
@today_events = Event.published.where("DATE(start_time) = ?", Date.current).order(start_time: :asc) @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) @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]) @other_events = Event.published.upcoming.where.not("DATE(start_time) IN (?)", [ Date.current, Date.current + 1 ]).order(start_time: :asc).page(params[:page])
end end
# Events page showing all published events with pagination # Events page showing all published events with pagination

View File

@@ -130,7 +130,7 @@ export default class extends Controller {
// Store cart data in session via AJAX // Store cart data in session via AJAX
async storeCartInSession(cartData) { async storeCartInSession(cartData) {
const storeCartUrl = `/events/${this.eventSlugValue}.${this.eventIdValue}/store_cart` const storeCartUrl = `/api/v1/events/${this.eventIdValue}/store_cart`
const response = await fetch(storeCartUrl, { const response = await fetch(storeCartUrl, {
method: 'POST', method: 'POST',

View File

@@ -39,7 +39,6 @@ Rails.application.routes.draw do
# === Events === # === Events ===
get "events", to: "events#index", as: "events" get "events", to: "events#index", as: "events"
get "events/:slug.:id", to: "events#show", as: "event" get "events/:slug.:id", to: "events#show", as: "event"
post "events/:slug.:id/store_cart", to: "events#store_cart", as: "store_cart"
# === Tickets === # === Tickets ===
get "events/:slug.:id/tickets/new", to: "tickets#new", as: "ticket_new" get "events/:slug.:id/tickets/new", to: "tickets#new", as: "ticket_new"
@@ -64,7 +63,11 @@ Rails.application.routes.draw do
namespace :api do namespace :api do
namespace :v1 do namespace :v1 do
# RESTful routes for event management # RESTful routes for event management
resources :events, only: [ :index, :show, :create, :update, :destroy ] resources :events, only: [ :index, :show, :create, :update, :destroy ] do
member do
post :store_cart
end
end
# resources :bundles, only: [ :index, :show, :create, :update, :destroy ] # resources :bundles, only: [ :index, :show, :create, :update, :destroy ]