-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP #2216 create event api for orangizer dashboard
- Loading branch information
Showing
6 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
33
app/controllers/spree/api/v2/organizer/events_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters