Skip to content

Commit

Permalink
Close #2226 organizer create ticket
Browse files Browse the repository at this point in the history
  • Loading branch information
SSambo12 committed Jan 8, 2025
1 parent 77b6b2c commit a182f90
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions app/controllers/spree/api/v2/organizer/tickets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Api
module V2
module Organizer
class TicketsController < ::Spree::Api::V2::Organizer::BaseController
before_action :set_store, only: %i[create]
before_action :set_event, only: %i[create]

def index
event = Spree::Taxon.find(params[:event_id])

Expand All @@ -24,9 +27,56 @@ def show
end
end

def create
resource = Spree::Product.new(product_params)
resource.stores << @store

resource.taxons << @event

if resource.save
render_serialized_payload(201) { serialize_resource(resource) }
else
render_error_payload(resource.errors.full_messages.to_sentence, 400)
end
end

private

def set_store
@store = Spree::Store.first
return if @store

render json: { error: 'Store not found' }, status: :not_found
end

def set_event
@event = Spree::Taxon.find_by(id: params[:event_id])
return if @event

render json: { error: 'Event not found' }, status: :not_found
end

def collection_serializer
::Spree::V2::Organizer::TicketSerializer
end

def resource_serializer
::Spree::V2::Organizer::TicketSerializer
end

def product_params
params.require(:product).permit(
:name,
:price,
:compare_at_price,
:available_on,
:kyc,
:description,
:shipping_category_id,
:product_type,
:status
)
end
end
end
end
Expand Down

0 comments on commit a182f90

Please sign in to comment.