-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Load closed shops in a separate request on /shops page #5156
Changes from all commits
af48cac
bc859cf
94f8ea2
003341e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Darkswarm.factory 'ShopsResource', ($resource) -> | ||
$resource('/api/shops/:id.json', {}, { | ||
'closed_shops': | ||
method: 'GET' | ||
isArray: true | ||
url: '/api/shops/closed_shops.json' | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,10 @@ | |
|
||
.more-controls { | ||
text-align: center; | ||
|
||
.spinner { | ||
height: 2.25em; | ||
margin-right: 0.5em; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
class ShopsController < BaseController | ||
respond_to :json | ||
skip_authorization_check only: [:show, :closed_shops] | ||
|
||
def show | ||
enterprise = Enterprise.find_by_id(params[:id]) | ||
|
||
render text: Api::EnterpriseShopfrontSerializer.new(enterprise).to_json, status: :ok | ||
end | ||
|
||
def closed_shops | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO this should be a filter specified by URL query param for an |
||
@active_distributor_ids = [] | ||
@earliest_closing_times = [] | ||
Comment on lines
+15
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do we need these for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are used in |
||
|
||
serialized_closed_shops = ActiveModel::ArraySerializer.new( | ||
ShopsListService.new.closed_shops, | ||
each_serializer: Api::EnterpriseSerializer, | ||
data: OpenFoodNetwork::EnterpriseInjectionData.new | ||
) | ||
|
||
render json: serialized_closed_shops | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
class ShopsListService | ||
def open_shops | ||
shops_list.ready_for_checkout.all | ||
end | ||
|
||
def closed_shops | ||
shops_list.not_ready_for_checkout.all | ||
end | ||
|
||
private | ||
|
||
def shops_list | ||
Enterprise | ||
.activated | ||
.visible | ||
.is_distributor | ||
.includes(address: [:state, :country]) | ||
.includes(:properties) | ||
.includes(supplied_products: :properties) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
module Api | ||
describe ShopsController, type: :controller do | ||
include AuthenticationWorkflow | ||
render_views | ||
|
||
context "as a non-authenticated user" do | ||
let!(:hub) { | ||
create(:distributor_enterprise, with_payment_and_shipping: true, name: 'Shopfront Test Hub') | ||
} | ||
let!(:producer) { create(:supplier_enterprise, name: 'Shopfront Test Producer') } | ||
let!(:category) { create(:taxon, name: 'Fruit') } | ||
let!(:product) { create(:product, supplier: producer, primary_taxon: category ) } | ||
let!(:relationship) { create(:enterprise_relationship, parent: hub, child: producer) } | ||
let!(:closed_hub1) { create(:distributor_enterprise) } | ||
let!(:closed_hub2) { create(:distributor_enterprise) } | ||
|
||
before do | ||
allow(controller).to receive(:spree_current_user) { nil } | ||
end | ||
|
||
describe "#show" do | ||
it "returns shopfront data for an enterprise" do | ||
spree_get :show, id: producer.id | ||
|
||
expect(json_response['name']).to eq 'Shopfront Test Producer' | ||
expect(json_response['hubs'][0]['name']).to eq 'Shopfront Test Hub' | ||
expect(json_response['supplied_taxons'][0]['name']).to eq 'Fruit' | ||
end | ||
end | ||
|
||
describe "#closed_shops" do | ||
it "returns data for all closed shops" do | ||
spree_get :closed_shops, nil | ||
|
||
expect(json_response).not_to match hub.name | ||
expect(json_response[0]['id']).to eq closed_hub1.id | ||
expect(json_response[1]['id']).to eq closed_hub2.id | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍