-
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.
Close #1979 create new api for organizer profile
- Loading branch information
1 parent
4b53968
commit 8157ab7
Showing
9 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
app/controllers/spree/api/v2/storefront/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,31 @@ | ||
module Spree | ||
module Api | ||
module V2 | ||
module Storefront | ||
class EventsController < Spree::Api::V2::ResourceController | ||
before_action :require_spree_current_user | ||
|
||
def collection | ||
organizer_query = SpreeCmCommissioner::OrganizerProfileEventQuery.new( | ||
user_id: spree_current_user.id, | ||
vendor_id: vendor.id, | ||
section: params[:section] || 'upcoming' | ||
) | ||
|
||
organizer_query.events.page(params[:page]).per(params[:per_page]) | ||
end | ||
|
||
def collection_serializer | ||
Spree::V2::Storefront::TaxonSerializer | ||
end | ||
|
||
private | ||
|
||
def vendor | ||
@vendor ||= Spree::Vendor.find_by(id: params[:vendor_id]) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
9 changes: 9 additions & 0 deletions
9
app/overrides/spree/admin/taxons/_form/vendor.html.erb.deface
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 @@ | ||
<!-- insert_before "erb[loud]:contains('field_container :permalink')" --> | ||
|
||
<div> | ||
<%= f.field_container :vendor_id do %> | ||
<%= label_tag :vendor_id, Spree.t(:vendors) %> | ||
<%= f.select :vendor_id, Spree::Vendor.pluck(:name, :id), { include_blank: true }, { class: 'select2-clear js-filterable' } %> | ||
<%= f.error_message_on :vendor_id, class: 'error-message' %> | ||
<% end %> | ||
</div> |
25 changes: 25 additions & 0 deletions
25
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,25 @@ | ||
module SpreeCmCommissioner | ||
class OrganizerProfileEventQuery | ||
attr_reader :user_id, :vendor_id, :section, :start_from_date | ||
|
||
# user_id: user ID, vendor_id: vendor ID, section: 'upcoming' or 'previous' | ||
def initialize(user_id:, vendor_id:, section:, start_from_date: nil) | ||
@user_id = user_id | ||
@vendor_id = vendor_id | ||
@section = section | ||
@start_from_date = start_from_date || Time.zone.now | ||
end | ||
|
||
def events | ||
taxons = Spree::Taxon.where(vendor_id: vendor_id) | ||
|
||
if section == 'upcoming' | ||
taxons.where('to_date >= ?', start_from_date) | ||
.order(from_date: :asc) | ||
else | ||
taxons.where('to_date < ?', start_from_date) | ||
.order(to_date: :desc) | ||
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
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,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 |
Empty file.
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