Skip to content

Commit

Permalink
WIP #2216 create event api for orangizer dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
phana25 committed Jan 6, 2025
1 parent e71fc8e commit e510064
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
13 changes: 13 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,13 @@
module Spree
module Api
module V2
module Organizer
class BaseController < ::Spree::Api::V2::BaseController
def render_serialized_payload(status = 200)
render json: yield, status: status, content_type: content_type
end
end
end
end
end
end
33 changes: 33 additions & 0 deletions app/controllers/spree/api/v2/organizer/events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Spree
module Api
module V2
module Organizer
class EventsController < ::Spree::Api::V2::Organizer::BaseController
def index
collection = Spree::Taxon.where(kind: params[:kind])
.is_child(ActiveModel::Type::Boolean.new.cast(params[:is_child]))
.is_leaf(ActiveModel::Type::Boolean.new.cast(params[:is_leaf]))
.page(params[:page])
.per(params[:per_page])
render_serialized_payload do
serialize_collection(collection)
end
end

def show
resource = Spree::Taxon.find(params[:id])
render_serialized_payload { serialize_resource(resource) }
end

def serialize_resource(resource)
Spree::V2::Organizer::EventSerializer.new(resource).serializable_hash
end

def serialize_collection(collection)
Spree::V2::Organizer::EventSerializer.new(collection).serializable_hash
end
end
end
end
end
end
3 changes: 3 additions & 0 deletions app/models/spree_cm_commissioner/taxon_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def self.prepended(base)

base.whitelisted_ransackable_attributes |= %w[kind]

base.scope :is_child, -> (value) { value ? where.not(parent_id: nil) : where(parent_id: nil) }
base.scope :is_leaf, -> (value) { value ? where.not(id: Spree::Taxon.joins(:children).select(:id)) : where(id: Spree::Taxon.joins(:children).select(:id)) }

base.enum purchasable_on: { both: 0, web: 1, app: 2 }
end

Expand Down
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
33 changes: 33 additions & 0 deletions app/serializers/spree/v2/organizer/event_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module Spree
module V2
module Organizer
class EventSerializer < BaseSerializer
attributes :name, :subtitle, :from_date, :to_date, :description, :kind

attribute :is_child, &:child?

attribute :is_leaf, &:leaf?

# Parent Association
belongs_to :parent,
record_type: :taxon,
serializer: Spree::V2::Storefront::TaxonSerializer

# Taxonomy Association
belongs_to :taxonomy,
record_type: :taxonomy,
serializer: Spree::V2::Storefront::TaxonomySerializer

# Children Association
has_many :children,
record_type: :taxon,
serializer: Spree::V2::Storefront::TaxonSerializer

has_one :category_icon, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
has_one :app_banner, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
has_one :web_banner, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
has_one :home_banner, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
end
end
end
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@
resources :places
end

namespace :organizer do
resources :events
resources :tickets
end

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

Expand Down

0 comments on commit e510064

Please sign in to comment.