Skip to content

Commit

Permalink
Close #2216 create event api for organizer dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
phana25 committed Jan 9, 2025
1 parent fb88505 commit 0f13231
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
13 changes: 0 additions & 13 deletions app/controllers/spree/api/v2/organizer/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,3 @@ def render_serialized_payload(status = 200)
end
end
end
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
14 changes: 10 additions & 4 deletions app/controllers/spree/api/v2/organizer/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def index
.page(params[:page])
.per(params[:per_page])
render_serialized_payload do
serialize_collection(collection)
serialize_collection.new(
collection,
collection_options(collection)
).serializable_hash
end
end

Expand All @@ -20,11 +23,14 @@ def show
end

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

def serialize_collection(collection)
Spree::V2::Organizer::EventSerializer.new(collection).serializable_hash
def serialize_collection
::Spree::V2::Organizer::EventSerializer
end
end
end
Expand Down
14 changes: 11 additions & 3 deletions app/models/spree_cm_commissioner/taxon_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SpreeCmCommissioner
module TaxonDecorator
def self.prepended(base)
def self.prepended(base) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
base.include SpreeCmCommissioner::TaxonKind

base.preference :background_color, :string
Expand Down Expand Up @@ -45,8 +45,16 @@ 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.scope :is_child, lambda { |value|
value ? where.not(parent_id: nil) : where(parent_id: nil)
}
base.scope :is_leaf, lambda { |value|
if value
where.not(id: Spree::Taxon.joins(:children).select(:id))
else
where(id: Spree::Taxon.joins(:children).select(:id))
end
}

base.enum purchasable_on: { both: 0, web: 1, app: 2 }
end
Expand Down
6 changes: 1 addition & 5 deletions app/serializers/spree/v2/organizer/event_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ module Spree
module V2
module Organizer
class EventSerializer < BaseSerializer
attributes :name, :subtitle, :from_date, :to_date, :description, :kind
attributes :name, :subtitle, :from_date, :to_date, :description, :kind, :vendor_id, :permalink

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
Expand Down

0 comments on commit 0f13231

Please sign in to comment.