feat: Implement event image upload system for promoters

- Add Active Storage migrations for file attachments
- Update Event model to handle image uploads with validation
- Replace image URL fields with file upload in forms
- Add client-side image preview with validation
- Update all views to display uploaded images properly
- Fix JSON serialization to prevent stack overflow in API
- Add custom image validation methods for format and size
- Include image processing variants for different display sizes
- Fix promotion code test infrastructure and Stripe configuration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
kbe
2025-09-30 00:41:03 +02:00
parent be7b3d5c18
commit 6be8b95ed3
22 changed files with 450 additions and 36 deletions

View File

@@ -14,14 +14,14 @@ module Api
# Retrieves all events sorted by creation date (most recent first)
def index
@events = Event.all.order(created_at: :desc)
render json: @events, status: :ok
render json: @events.map { |e| event_json(e) }, status: :ok
end
# GET /api/v1/events/:id
# Retrieves a single event by its ID
# Returns 404 if the event is not found
def show
render json: @event, status: :ok
render json: event_json(@event), status: :ok
end
# POST /api/v1/events
@@ -31,7 +31,7 @@ module Api
def create
@event = Event.new(event_params)
if @event.save
render json: @event, status: :created
render json: event_json(@event), status: :created
else
render json: { errors: @event.errors.full_messages }, status: :unprocessable_entity
end
@@ -43,7 +43,7 @@ module Api
# Returns 422 Unprocessable Entity with error messages on failure
def update
if @event.update(event_params)
render json: @event, status: :ok
render json: event_json(@event), status: :ok
else
render json: { errors: @event.errors.full_messages }, status: :unprocessable_entity
end
@@ -73,6 +73,32 @@ module Api
private
# Helper method to serialize event data safely
def event_json(event)
{
id: event.id,
name: event.name,
slug: event.slug,
description: event.description,
state: event.state,
venue_name: event.venue_name,
venue_address: event.venue_address,
start_time: event.start_time,
end_time: event.end_time,
latitude: event.latitude,
longitude: event.longitude,
featured: event.featured,
created_at: event.created_at,
updated_at: event.updated_at,
user: {
id: event.user.id,
email: event.user.email,
first_name: event.user.first_name,
last_name: event.user.last_name
}
}
end
# Finds an event by its ID or returns 404 Not Found
# Used as before_action for the show, update, and destroy actions
def set_event

View File

@@ -164,6 +164,8 @@ class OrdersController < ApplicationController
flash[:alert] = "Erreur lors de la création de la session de paiement"
end
end
render :checkout
end
# Increment payment attempt - called via AJAX when user clicks pay button

View File

@@ -29,6 +29,8 @@ class Promoter::EventsController < ApplicationController
if @event.save
redirect_to promoter_event_path(@event), notice: "Event créé avec succès!"
else
# If validation fails and an image was attached, purge it
@event.image.purge if @event.image.attached?
render :new, status: :unprocessable_entity
end
end