-
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 #1979 create new api for organizer profile
- Loading branch information
1 parent
83503b7
commit 18ae891
Showing
5 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
app/controllers/spree/api/v2/storefront/vendors_controller_decorator.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,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
21
app/queries/spree_cm_commissioner/organizer_profile_event_query.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,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 |
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 |
---|---|---|
|
@@ -32,6 +32,8 @@ | |
end | ||
end | ||
|
||
resources :events | ||
|
||
resources :vendor_photos do | ||
collection do | ||
post :update_positions | ||
|
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,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 |