feat: Refactor cart storage to use API architecture
Move store_cart functionality from main EventsController to API namespace: - Add store_cart method to Api::V1::EventsController with API key bypass - Remove store_cart from main EventsController - Update routes to use RESTful API endpoint structure - Maintain session-based cart storage for frontend compatibility
This commit is contained in:
@@ -4,8 +4,11 @@
|
||||
module Api
|
||||
module V1
|
||||
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
|
||||
before_action :set_event, only: [ :show, :update, :destroy ]
|
||||
before_action :set_event, only: [ :show, :update, :destroy, :store_cart ]
|
||||
|
||||
# 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)
|
||||
@@ -54,6 +57,18 @@ module Api
|
||||
head :no_content
|
||||
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
|
||||
|
||||
# Trouve un événement par son ID ou retourne 404 Introuvable
|
||||
|
||||
Reference in New Issue
Block a user