Skip to content

Commit

Permalink
Close #2219 Organizer fetch ticket (#2220)
Browse files Browse the repository at this point in the history
  • Loading branch information
SSambo12 authored Jan 8, 2025
1 parent e71fc8e commit 77b6b2c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/spree/api/v2/organizer/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Spree
module Api
module V2
module Organizer
class BaseController < ::Spree::Api::V2::BaseController
include Spree::Api::V2::CollectionOptionsHelpers

def render_serialized_payload(status = 200)
render json: yield, status: status, content_type: content_type
end
end
end
end
end
end
34 changes: 34 additions & 0 deletions app/controllers/spree/api/v2/organizer/tickets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module Spree
module Api
module V2
module Organizer
class TicketsController < ::Spree::Api::V2::Organizer::BaseController
def index
event = Spree::Taxon.find(params[:event_id])

resource = event.products.page(params[:page]).per(params[:per_page])

render_serialized_payload do
collection_serializer.new(
resource,
collection_options(resource)
).serializable_hash
end
end

def show
resource = Spree::Product.find(params[:id])

render_serialized_payload do
Spree::V2::Organizer::TicketSerializer.new(resource).serializable_hash
end
end

def collection_serializer
::Spree::V2::Organizer::TicketSerializer
end
end
end
end
end
end
9 changes: 9 additions & 0 deletions app/serializers/spree/v2/organizer/base_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Spree
module V2
module Organizer
class BaseSerializer
include JSONAPI::Serializer
end
end
end
end
10 changes: 10 additions & 0 deletions app/serializers/spree/v2/organizer/ticket_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Spree
module V2
module Organizer
class TicketSerializer < BaseSerializer
set_type :ticket
attributes :name, :price, :compare_at_price, :available_on, :kyc, :description, :shipping_category_id, :product_type, :status
end
end
end
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,10 @@
resources :places
end

namespace :organizer do
resources :tickets
end

namespace :storefront do
resources :waiting_room_sessions, only: :create

Expand Down

0 comments on commit 77b6b2c

Please sign in to comment.