Skip to content

Commit

Permalink
WIP #1979 create new api for organizer profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreyleak-Deth committed Sep 27, 2024
1 parent 83503b7 commit 18ae891
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Spree
module Api
module V2
module Storefront
class VendorsControllerDecorator
before_action :require_spree_current_user

def collection
SpreeCmCommissioner::OrganizerProfileEventQuery.new(
user_id: spree_current_user.id,
section: params[:section] || 'upcoming'
).events
end

def collection_serializer
Spree::V2::Storefront::VendorSerializerDecorator
end
end
end
end
end
end
21 changes: 21 additions & 0 deletions app/queries/spree_cm_commissioner/organizer_profile_event_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module SpreeCmCommissioner
class OrganizerProfileEventQuery
attr_reader :user_id, :section, :start_from_date

# user_id:, section: 'upcoming | previous'
def initialize(user_id:, section:, start_from_date: nil)
@user_id = user_id
@section = section
@start_from_date = start_from_date || Time.zone.now
end

def events
taxons = Spree::Taxon.joins(:user_events).where(user_events: { user_id: user_id })

query = section == 'upcoming' ? 'to_date >= ?' : 'to_date < ?'
order = section == 'upcoming' ? { from_date: :asc } : { to_date: :desc }

taxons.where(query, start_from_date).order(order)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def self.prepended(base)
base.has_many :vendor_kind_option_values, serializer: :option_value
base.has_many :auto_apply_promotions, serializer: ::SpreeCmCommissioner::V2::Storefront::PromotionSerializer
base.has_many :active_promotions, serializer: ::SpreeCmCommissioner::V2::Storefront::PromotionSerializer
base.has_many :taxon

base.has_one :default_state, serializer: :state
base.has_one :logo, serializer: ::SpreeCmCommissioner::V2::Storefront::AssetSerializer
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
end
end

resources :events

resources :vendor_photos do
collection do
post :update_positions
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240926044328_add_vendor_to_spree_taxon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVendorToSpreeTaxon < ActiveRecord::Migration[7.0]
def change
add_reference :spree_taxons, :vendor, index: true, foreign_key: { to_table: :spree_vendors }, if_not_exists: true
end
end

0 comments on commit 18ae891

Please sign in to comment.