develop #3
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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,7 +25,7 @@ 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)
|
||||||
|
|
||||||
|
|||||||
@@ -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',
|
||||||
|
|||||||
@@ -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 ]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user