spree_api 3.0.10 → 3.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/spree/api/base_controller.rb +21 -22
- data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
- data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
- data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
- data/app/controllers/spree/api/v1/images_controller.rb +56 -0
- data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
- data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
- data/app/controllers/spree/api/v1/orders_controller.rb +137 -0
- data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
- data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/spree/api/v1/products_controller.rb +126 -0
- data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
- data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
- data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
- data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
- data/app/controllers/spree/api/v1/states_controller.rb +37 -0
- data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
- data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
- data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
- data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
- data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
- data/app/controllers/spree/api/v1/users_controller.rb +60 -0
- data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
- data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
- data/app/helpers/spree/api/api_helpers.rb +3 -2
- data/app/views/spree/api/{addresses → v1/addresses}/show.v1.rabl +0 -0
- data/app/views/spree/api/{adjustments → v1/adjustments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/money.v1.rabl +0 -0
- data/app/views/spree/api/{config → v1/config}/show.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/index.v1.rabl +0 -0
- data/app/views/spree/api/{countries → v1/countries}/show.v1.rabl +0 -0
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/index.v1.rabl +1 -1
- data/app/views/spree/api/{credit_cards → v1/credit_cards}/show.v1.rabl +0 -0
- data/app/views/spree/api/{images → v1/images}/index.v1.rabl +1 -1
- data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
- data/app/views/spree/api/{images → v1/images}/show.v1.rabl +0 -0
- data/app/views/spree/api/{inventory_units → v1/inventory_units}/show.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/new.v1.rabl +0 -0
- data/app/views/spree/api/{line_items → v1/line_items}/show.v1.rabl +3 -3
- data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_types → v1/option_types}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
- data/app/views/spree/api/{option_values → v1/option_values}/show.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/address.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/canceled.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/cart.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/complete.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_apply_coupon.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/could_not_transition.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/index.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/invalid_shipping_method.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{orders → v1/orders}/order.v1.rabl +1 -0
- data/app/views/spree/api/{orders → v1/orders}/payment.v1.rabl +0 -0
- data/app/views/spree/api/{orders → v1/orders}/show.v1.rabl +9 -9
- data/app/views/spree/api/{payments → v1/payments}/credit_over_limit.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/index.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/new.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/show.v1.rabl +0 -0
- data/app/views/spree/api/{payments → v1/payments}/update_forbidden.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{product_properties → v1/product_properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/index.v1.rabl +1 -1
- data/app/views/spree/api/{products → v1/products}/new.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/product.v1.rabl +0 -0
- data/app/views/spree/api/{products → v1/products}/show.v1.rabl +3 -3
- data/app/views/spree/api/{promotions → v1/promotions}/handler.v1.rabl +0 -0
- data/app/views/spree/api/{promotions → v1/promotions}/show.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/index.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/new.v1.rabl +0 -0
- data/app/views/spree/api/{properties → v1/properties}/show.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/index.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/new.v1.rabl +0 -0
- data/app/views/spree/api/{return_authorizations → v1/return_authorizations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{shared → v1/shared}/stock_location_required.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/big.v1.rabl +7 -7
- data/app/views/spree/api/{shipments → v1/shipments}/cannot_ready_shipment.v1.rabl +0 -0
- data/app/views/spree/api/{shipments → v1/shipments}/mine.v1.rabl +1 -1
- data/app/views/spree/api/{shipments → v1/shipments}/show.v1.rabl +3 -3
- data/app/views/spree/api/{shipments → v1/shipments}/small.v1.rabl +3 -3
- data/app/views/spree/api/{shipping_rates → v1/shipping_rates}/show.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/index.v1.rabl +0 -0
- data/app/views/spree/api/{states → v1/states}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_items → v1/stock_items}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_items → v1/stock_items}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_locations → v1/stock_locations}/show.v1.rabl +0 -0
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/index.v1.rabl +1 -1
- data/app/views/spree/api/{stock_movements → v1/stock_movements}/show.v1.rabl +1 -1
- data/app/views/spree/api/{stores → v1/stores}/index.v1.rabl +0 -0
- data/app/views/spree/api/{stores → v1/stores}/show.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/nested.v1.rabl +1 -1
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxonomies → v1/taxonomies}/show.v1.rabl +4 -4
- data/app/views/spree/api/{taxons → v1/taxons}/index.v1.rabl +1 -1
- data/app/views/spree/api/{taxons → v1/taxons}/jstree.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/new.v1.rabl +0 -0
- data/app/views/spree/api/{taxons → v1/taxons}/show.v1.rabl +0 -0
- data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
- data/app/views/spree/api/{users → v1/users}/index.v1.rabl +1 -1
- data/app/views/spree/api/{users → v1/users}/new.v1.rabl +0 -0
- data/app/views/spree/api/{users → v1/users}/show.v1.rabl +2 -2
- data/app/views/spree/api/{variants → v1/variants}/big.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/index.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/new.v1.rabl +0 -0
- data/app/views/spree/api/{variants → v1/variants}/show.v1.rabl +1 -1
- data/app/views/spree/api/{variants → v1/variants}/small.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/index.v1.rabl +1 -1
- data/app/views/spree/api/{zones → v1/zones}/show.v1.rabl +0 -0
- data/config/routes.rb +85 -88
- data/spec/controllers/spree/api/base_controller_spec.rb +14 -42
- data/spec/controllers/spree/api/{addresses_controller_spec.rb → v1/addresses_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{checkouts_controller_spec.rb → v1/checkouts_controller_spec.rb} +51 -3
- data/spec/controllers/spree/api/{classifications_controller_spec.rb → v1/classifications_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{countries_controller_spec.rb → v1/countries_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{credit_cards_controller_spec.rb → v1/credit_cards_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{images_controller_spec.rb → v1/images_controller_spec.rb} +23 -1
- data/spec/controllers/spree/api/{inventory_units_controller_spec.rb → v1/inventory_units_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{line_items_controller_spec.rb → v1/line_items_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{option_types_controller_spec.rb → v1/option_types_controller_spec.rb} +9 -3
- data/spec/controllers/spree/api/{option_values_controller_spec.rb → v1/option_values_controller_spec.rb} +8 -2
- data/spec/controllers/spree/api/{orders_controller_spec.rb → v1/orders_controller_spec.rb} +29 -8
- data/spec/controllers/spree/api/{payments_controller_spec.rb → v1/payments_controller_spec.rb} +2 -2
- data/spec/controllers/spree/api/{product_properties_controller_spec.rb → v1/product_properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{products_controller_spec.rb → v1/products_controller_spec.rb} +5 -5
- data/spec/controllers/spree/api/{promotion_application_spec.rb → v1/promotion_application_spec.rb} +2 -2
- data/spec/controllers/spree/api/{promotions_controller_spec.rb → v1/promotions_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{properties_controller_spec.rb → v1/properties_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{return_authorizations_controller_spec.rb → v1/return_authorizations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{shipments_controller_spec.rb → v1/shipments_controller_spec.rb} +4 -4
- data/spec/controllers/spree/api/{states_controller_spec.rb → v1/states_controller_spec.rb} +14 -10
- data/spec/controllers/spree/api/{stock_items_controller_spec.rb → v1/stock_items_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_locations_controller_spec.rb → v1/stock_locations_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stock_movements_controller_spec.rb → v1/stock_movements_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{stores_controller_spec.rb → v1/stores_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxonomies_controller_spec.rb → v1/taxonomies_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{taxons_controller_spec.rb → v1/taxons_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{unauthenticated_products_controller_spec.rb → v1/unauthenticated_products_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{users_controller_spec.rb → v1/users_controller_spec.rb} +1 -1
- data/spec/controllers/spree/api/{variants_controller_spec.rb → v1/variants_controller_spec.rb} +3 -3
- data/spec/controllers/spree/api/{zones_controller_spec.rb → v1/zones_controller_spec.rb} +7 -5
- data/spec/requests/rabl_cache_spec.rb +2 -2
- data/spec/requests/ransackable_attributes_spec.rb +6 -6
- data/spec/requests/version_spec.rb +19 -0
- data/spree_api.gemspec +1 -1
- metadata +188 -185
- data/CHANGELOG.md +0 -3
- data/app/controllers/spree/api/addresses_controller.rb +0 -43
- data/app/controllers/spree/api/checkouts_controller.rb +0 -98
- data/app/controllers/spree/api/classifications_controller.rb +0 -18
- data/app/controllers/spree/api/countries_controller.rb +0 -23
- data/app/controllers/spree/api/credit_cards_controller.rb +0 -25
- data/app/controllers/spree/api/images_controller.rb +0 -47
- data/app/controllers/spree/api/inventory_units_controller.rb +0 -52
- data/app/controllers/spree/api/line_items_controller.rb +0 -69
- data/app/controllers/spree/api/option_types_controller.rb +0 -49
- data/app/controllers/spree/api/option_values_controller.rb +0 -58
- data/app/controllers/spree/api/orders_controller.rb +0 -130
- data/app/controllers/spree/api/payments_controller.rb +0 -80
- data/app/controllers/spree/api/product_properties_controller.rb +0 -72
- data/app/controllers/spree/api/products_controller.rb +0 -124
- data/app/controllers/spree/api/promotions_controller.rb +0 -26
- data/app/controllers/spree/api/properties_controller.rb +0 -70
- data/app/controllers/spree/api/return_authorizations_controller.rb +0 -69
- data/app/controllers/spree/api/shipments_controller.rb +0 -149
- data/app/controllers/spree/api/states_controller.rb +0 -38
- data/app/controllers/spree/api/stock_items_controller.rb +0 -75
- data/app/controllers/spree/api/stock_locations_controller.rb +0 -50
- data/app/controllers/spree/api/stock_movements_controller.rb +0 -43
- data/app/controllers/spree/api/stores_controller.rb +0 -55
- data/app/controllers/spree/api/taxonomies_controller.rb +0 -64
- data/app/controllers/spree/api/taxons_controller.rb +0 -93
- data/app/controllers/spree/api/users_controller.rb +0 -56
- data/app/controllers/spree/api/variants_controller.rb +0 -73
- data/app/controllers/spree/api/zones_controller.rb +0 -49
- data/app/models/spree/option_value_decorator.rb +0 -9
- data/app/views/spree/api/option_types/index.v1.rabl +0 -3
- data/app/views/spree/api/option_values/index.v1.rabl +0 -3
- data/app/views/spree/api/taxons/taxons.v1.rabl +0 -5
@@ -0,0 +1,37 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StatesController < Spree::Api::BaseController
|
5
|
+
skip_before_action :authenticate_user
|
6
|
+
|
7
|
+
def index
|
8
|
+
@states = scope.ransack(params[:q]).result.includes(:country)
|
9
|
+
|
10
|
+
if params[:page] || params[:per_page]
|
11
|
+
@states = @states.page(params[:page]).per(params[:per_page])
|
12
|
+
end
|
13
|
+
|
14
|
+
state = @states.last
|
15
|
+
if stale?(state)
|
16
|
+
respond_with(@states)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@state = scope.find(params[:id])
|
22
|
+
respond_with(@state)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def scope
|
27
|
+
if params[:country_id]
|
28
|
+
@country = Country.accessible_by(current_ability, :read).find(params[:country_id])
|
29
|
+
return @country.states.accessible_by(current_ability, :read).order('name ASC')
|
30
|
+
else
|
31
|
+
return State.accessible_by(current_ability, :read).order('name ASC')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StockItemsController < Spree::Api::BaseController
|
5
|
+
before_action :stock_location, except: [:update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
@stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
9
|
+
respond_with(@stock_items)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
@stock_item = scope.find(params[:id])
|
14
|
+
respond_with(@stock_item)
|
15
|
+
end
|
16
|
+
|
17
|
+
def create
|
18
|
+
authorize! :create, StockItem
|
19
|
+
|
20
|
+
count_on_hand = 0
|
21
|
+
if params[:stock_item].has_key?(:count_on_hand)
|
22
|
+
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
@stock_item = scope.new(stock_item_params)
|
26
|
+
if @stock_item.save
|
27
|
+
@stock_item.adjust_count_on_hand(count_on_hand)
|
28
|
+
respond_with(@stock_item, status: 201, default_template: :show)
|
29
|
+
else
|
30
|
+
invalid_resource!(@stock_item)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def update
|
35
|
+
@stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])
|
36
|
+
|
37
|
+
count_on_hand = 0
|
38
|
+
if params[:stock_item].has_key?(:count_on_hand)
|
39
|
+
count_on_hand = params[:stock_item][:count_on_hand].to_i
|
40
|
+
params[:stock_item].delete(:count_on_hand)
|
41
|
+
end
|
42
|
+
|
43
|
+
updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)
|
44
|
+
: @stock_item.adjust_count_on_hand(count_on_hand)
|
45
|
+
|
46
|
+
if updated
|
47
|
+
respond_with(@stock_item, status: 200, default_template: :show)
|
48
|
+
else
|
49
|
+
invalid_resource!(@stock_item)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
@stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])
|
55
|
+
@stock_item.destroy
|
56
|
+
respond_with(@stock_item, status: 204)
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def stock_location
|
62
|
+
render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
63
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
64
|
+
end
|
65
|
+
|
66
|
+
def scope
|
67
|
+
includes = {:variant => [{ :option_values => :option_type }, :product] }
|
68
|
+
@stock_location.stock_items.accessible_by(current_ability, :read).includes(includes)
|
69
|
+
end
|
70
|
+
|
71
|
+
def stock_item_params
|
72
|
+
params.require(:stock_item).permit(permitted_stock_item_attributes)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StockLocationsController < Spree::Api::BaseController
|
5
|
+
def index
|
6
|
+
authorize! :read, StockLocation
|
7
|
+
@stock_locations = StockLocation.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
8
|
+
respond_with(@stock_locations)
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
respond_with(stock_location)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
authorize! :create, StockLocation
|
17
|
+
@stock_location = StockLocation.new(stock_location_params)
|
18
|
+
if @stock_location.save
|
19
|
+
respond_with(@stock_location, status: 201, default_template: :show)
|
20
|
+
else
|
21
|
+
invalid_resource!(@stock_location)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
authorize! :update, stock_location
|
27
|
+
if stock_location.update_attributes(stock_location_params)
|
28
|
+
respond_with(stock_location, status: 200, default_template: :show)
|
29
|
+
else
|
30
|
+
invalid_resource!(stock_location)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def destroy
|
35
|
+
authorize! :destroy, stock_location
|
36
|
+
stock_location.destroy
|
37
|
+
respond_with(stock_location, :status => 204)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def stock_location
|
43
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
def stock_location_params
|
47
|
+
params.require(:stock_location).permit(permitted_stock_location_attributes)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StockMovementsController < Spree::Api::BaseController
|
5
|
+
before_action :stock_location, except: [:update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
authorize! :read, StockMovement
|
9
|
+
@stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
10
|
+
respond_with(@stock_movements)
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@stock_movement = scope.find(params[:id])
|
15
|
+
respond_with(@stock_movement)
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
authorize! :create, StockMovement
|
20
|
+
@stock_movement = scope.new(stock_movement_params)
|
21
|
+
if @stock_movement.save
|
22
|
+
respond_with(@stock_movement, status: 201, default_template: :show)
|
23
|
+
else
|
24
|
+
invalid_resource!(@stock_movement)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def stock_location
|
31
|
+
render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
32
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :read).find(params[:stock_location_id])
|
33
|
+
end
|
34
|
+
|
35
|
+
def scope
|
36
|
+
@stock_location.stock_movements.accessible_by(current_ability, :read)
|
37
|
+
end
|
38
|
+
|
39
|
+
def stock_movement_params
|
40
|
+
params.require(:stock_movement).permit(permitted_stock_movement_attributes)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StoresController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
before_action :get_store, except: [:index, :create]
|
7
|
+
|
8
|
+
def index
|
9
|
+
authorize! :read, Store
|
10
|
+
@stores = Store.accessible_by(current_ability, :read).all
|
11
|
+
respond_with(@stores)
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
authorize! :create, Store
|
16
|
+
@store = Store.new(store_params)
|
17
|
+
@store.code = params[:store][:code]
|
18
|
+
if @store.save
|
19
|
+
respond_with(@store, status: 201, default_template: :show)
|
20
|
+
else
|
21
|
+
invalid_resource!(@store)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
authorize! :update, @store
|
27
|
+
if @store.update_attributes(store_params)
|
28
|
+
respond_with(@store, status: 200, default_template: :show)
|
29
|
+
else
|
30
|
+
invalid_resource!(@store)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def show
|
35
|
+
authorize! :read, @store
|
36
|
+
respond_with(@store)
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
authorize! :destroy, @store
|
41
|
+
@store.destroy
|
42
|
+
respond_with(@store, status: 204)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def get_store
|
48
|
+
@store = Store.find(params[:id])
|
49
|
+
end
|
50
|
+
|
51
|
+
def store_params
|
52
|
+
params.require(:store).permit(permitted_store_attributes)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class TaxonomiesController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
def index
|
7
|
+
respond_with(taxonomies)
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
respond_with(taxonomy)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Because JSTree wants parameters in a *slightly* different format
|
15
|
+
def jstree
|
16
|
+
show
|
17
|
+
end
|
18
|
+
|
19
|
+
def create
|
20
|
+
authorize! :create, Taxonomy
|
21
|
+
@taxonomy = Taxonomy.new(taxonomy_params)
|
22
|
+
if @taxonomy.save
|
23
|
+
respond_with(@taxonomy, :status => 201, :default_template => :show)
|
24
|
+
else
|
25
|
+
invalid_resource!(@taxonomy)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def update
|
30
|
+
authorize! :update, taxonomy
|
31
|
+
if taxonomy.update_attributes(taxonomy_params)
|
32
|
+
respond_with(taxonomy, :status => 200, :default_template => :show)
|
33
|
+
else
|
34
|
+
invalid_resource!(taxonomy)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
authorize! :destroy, taxonomy
|
40
|
+
taxonomy.destroy
|
41
|
+
respond_with(taxonomy, :status => 204)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def taxonomies
|
47
|
+
@taxonomies = Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
|
48
|
+
ransack(params[:q]).result.
|
49
|
+
page(params[:page]).per(params[:per_page])
|
50
|
+
end
|
51
|
+
|
52
|
+
def taxonomy
|
53
|
+
@taxonomy ||= Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
54
|
+
end
|
55
|
+
|
56
|
+
def taxonomy_params
|
57
|
+
if params[:taxonomy] && !params[:taxonomy].empty?
|
58
|
+
params.require(:taxonomy).permit(permitted_taxonomy_attributes)
|
59
|
+
else
|
60
|
+
{}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class TaxonsController < Spree::Api::BaseController
|
5
|
+
def index
|
6
|
+
if taxonomy
|
7
|
+
@taxons = taxonomy.root.children
|
8
|
+
else
|
9
|
+
if params[:ids]
|
10
|
+
@taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
11
|
+
else
|
12
|
+
@taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
17
|
+
respond_with(@taxons)
|
18
|
+
end
|
19
|
+
|
20
|
+
def show
|
21
|
+
@taxon = taxon
|
22
|
+
respond_with(@taxon)
|
23
|
+
end
|
24
|
+
|
25
|
+
def jstree
|
26
|
+
show
|
27
|
+
end
|
28
|
+
|
29
|
+
def create
|
30
|
+
authorize! :create, Taxon
|
31
|
+
@taxon = Spree::Taxon.new(taxon_params)
|
32
|
+
@taxon.taxonomy_id = params[:taxonomy_id]
|
33
|
+
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
34
|
+
|
35
|
+
if taxonomy.nil?
|
36
|
+
@taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
|
37
|
+
invalid_resource!(@taxon) and return
|
38
|
+
end
|
39
|
+
|
40
|
+
@taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
|
41
|
+
|
42
|
+
if @taxon.save
|
43
|
+
respond_with(@taxon, status: 201, default_template: :show)
|
44
|
+
else
|
45
|
+
invalid_resource!(@taxon)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def update
|
50
|
+
authorize! :update, taxon
|
51
|
+
if taxon.update_attributes(taxon_params)
|
52
|
+
respond_with(taxon, status: 200, default_template: :show)
|
53
|
+
else
|
54
|
+
invalid_resource!(taxon)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def destroy
|
59
|
+
authorize! :destroy, taxon
|
60
|
+
taxon.destroy
|
61
|
+
respond_with(taxon, status: 204)
|
62
|
+
end
|
63
|
+
|
64
|
+
def products
|
65
|
+
# Returns the products sorted by their position with the classification
|
66
|
+
# Products#index does not do the sorting.
|
67
|
+
taxon = Spree::Taxon.find(params[:id])
|
68
|
+
@products = taxon.products.ransack(params[:q]).result
|
69
|
+
@products = @products.page(params[:page]).per(params[:per_page] || 500)
|
70
|
+
render "spree/api/v1/products/index"
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def taxonomy
|
76
|
+
if params[:taxonomy_id].present?
|
77
|
+
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def taxon
|
82
|
+
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
|
83
|
+
end
|
84
|
+
|
85
|
+
def taxon_params
|
86
|
+
if params[:taxon] && !params[:taxon].empty?
|
87
|
+
params.require(:taxon).permit(permitted_taxon_attributes)
|
88
|
+
else
|
89
|
+
{}
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Spree
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class UsersController < Spree::Api::BaseController
|
5
|
+
|
6
|
+
rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
|
7
|
+
|
8
|
+
def index
|
9
|
+
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
10
|
+
respond_with(@users)
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
respond_with(user)
|
15
|
+
end
|
16
|
+
|
17
|
+
def new
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
authorize! :create, Spree.user_class
|
22
|
+
@user = Spree.user_class.new(user_params)
|
23
|
+
if @user.save
|
24
|
+
respond_with(@user, :status => 201, :default_template => :show)
|
25
|
+
else
|
26
|
+
invalid_resource!(@user)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
authorize! :update, user
|
32
|
+
if user.update_attributes(user_params)
|
33
|
+
respond_with(user, :status => 200, :default_template => :show)
|
34
|
+
else
|
35
|
+
invalid_resource!(user)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
authorize! :destroy, user
|
41
|
+
user.destroy
|
42
|
+
respond_with(user, :status => 204)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def user
|
48
|
+
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_params
|
52
|
+
params.require(:user).permit(permitted_user_attributes |
|
53
|
+
[bill_address_attributes: permitted_address_attributes,
|
54
|
+
ship_address_attributes: permitted_address_attributes])
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|