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
@@ -1,64 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class TaxonomiesController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
def index
|
6
|
-
respond_with(taxonomies)
|
7
|
-
end
|
8
|
-
|
9
|
-
def show
|
10
|
-
respond_with(taxonomy)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Because JSTree wants parameters in a *slightly* different format
|
14
|
-
def jstree
|
15
|
-
show
|
16
|
-
end
|
17
|
-
|
18
|
-
def create
|
19
|
-
authorize! :create, Spree::Taxonomy
|
20
|
-
@taxonomy = Spree::Taxonomy.new(taxonomy_params)
|
21
|
-
if @taxonomy.save
|
22
|
-
respond_with(@taxonomy, :status => 201, :default_template => :show)
|
23
|
-
else
|
24
|
-
invalid_resource!(@taxonomy)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
authorize! :update, taxonomy
|
30
|
-
if taxonomy.update_attributes(taxonomy_params)
|
31
|
-
respond_with(taxonomy, :status => 200, :default_template => :show)
|
32
|
-
else
|
33
|
-
invalid_resource!(taxonomy)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def destroy
|
38
|
-
authorize! :destroy, taxonomy
|
39
|
-
taxonomy.destroy
|
40
|
-
respond_with(taxonomy, :status => 204)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def taxonomies
|
46
|
-
@taxonomies = Spree::Taxonomy.accessible_by(current_ability, :read).order('name').includes(:root => :children).
|
47
|
-
ransack(params[:q]).result.
|
48
|
-
page(params[:page]).per(params[:per_page])
|
49
|
-
end
|
50
|
-
|
51
|
-
def taxonomy
|
52
|
-
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:id])
|
53
|
-
end
|
54
|
-
|
55
|
-
def taxonomy_params
|
56
|
-
if params[:taxonomy] && !params[:taxonomy].empty?
|
57
|
-
params.require(:taxonomy).permit(permitted_taxonomy_attributes)
|
58
|
-
else
|
59
|
-
{}
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class TaxonsController < Spree::Api::BaseController
|
4
|
-
def index
|
5
|
-
if taxonomy
|
6
|
-
@taxons = taxonomy.root.children
|
7
|
-
else
|
8
|
-
if params[:ids]
|
9
|
-
@taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).where(id: params[:ids].split(','))
|
10
|
-
else
|
11
|
-
@taxons = Spree::Taxon.includes(:children).accessible_by(current_ability, :read).order(:taxonomy_id, :lft).ransack(params[:q]).result
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
16
|
-
respond_with(@taxons)
|
17
|
-
end
|
18
|
-
|
19
|
-
def show
|
20
|
-
@taxon = taxon
|
21
|
-
respond_with(@taxon)
|
22
|
-
end
|
23
|
-
|
24
|
-
def jstree
|
25
|
-
show
|
26
|
-
end
|
27
|
-
|
28
|
-
def create
|
29
|
-
authorize! :create, Spree::Taxon
|
30
|
-
@taxon = Spree::Taxon.new(taxon_params)
|
31
|
-
@taxon.taxonomy_id = params[:taxonomy_id]
|
32
|
-
taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])
|
33
|
-
|
34
|
-
if taxonomy.nil?
|
35
|
-
@taxon.errors[:taxonomy_id] = I18n.t(:invalid_taxonomy_id, scope: 'spree.api')
|
36
|
-
invalid_resource!(@taxon) and return
|
37
|
-
end
|
38
|
-
|
39
|
-
@taxon.parent_id = taxonomy.root.id unless params[:taxon][:parent_id]
|
40
|
-
|
41
|
-
if @taxon.save
|
42
|
-
respond_with(@taxon, status: 201, default_template: :show)
|
43
|
-
else
|
44
|
-
invalid_resource!(@taxon)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def update
|
49
|
-
authorize! :update, taxon
|
50
|
-
if taxon.update_attributes(taxon_params)
|
51
|
-
respond_with(taxon, status: 200, default_template: :show)
|
52
|
-
else
|
53
|
-
invalid_resource!(taxon)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def destroy
|
58
|
-
authorize! :destroy, taxon
|
59
|
-
taxon.destroy
|
60
|
-
respond_with(taxon, status: 204)
|
61
|
-
end
|
62
|
-
|
63
|
-
def products
|
64
|
-
# Returns the products sorted by their position with the classification
|
65
|
-
# Products#index does not do the sorting.
|
66
|
-
taxon = Spree::Taxon.find(params[:id])
|
67
|
-
@products = taxon.products.ransack(params[:q]).result
|
68
|
-
@products = @products.page(params[:page]).per(params[:per_page] || 500)
|
69
|
-
render "spree/api/products/index"
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def taxonomy
|
75
|
-
if params[:taxonomy_id].present?
|
76
|
-
@taxonomy ||= Spree::Taxonomy.accessible_by(current_ability, :read).find(params[:taxonomy_id])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def taxon
|
81
|
-
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :read).find(params[:id])
|
82
|
-
end
|
83
|
-
|
84
|
-
def taxon_params
|
85
|
-
if params[:taxon] && !params[:taxon].empty?
|
86
|
-
params.require(:taxon).permit(permitted_taxon_attributes)
|
87
|
-
else
|
88
|
-
{}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class UsersController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
def index
|
6
|
-
@users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
7
|
-
respond_with(@users)
|
8
|
-
end
|
9
|
-
|
10
|
-
def show
|
11
|
-
respond_with(user)
|
12
|
-
end
|
13
|
-
|
14
|
-
def new
|
15
|
-
end
|
16
|
-
|
17
|
-
def create
|
18
|
-
authorize! :create, Spree.user_class
|
19
|
-
@user = Spree.user_class.new(user_params)
|
20
|
-
if @user.save
|
21
|
-
respond_with(@user, :status => 201, :default_template => :show)
|
22
|
-
else
|
23
|
-
invalid_resource!(@user)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def update
|
28
|
-
authorize! :update, user
|
29
|
-
if user.update_attributes(user_params)
|
30
|
-
respond_with(user, :status => 200, :default_template => :show)
|
31
|
-
else
|
32
|
-
invalid_resource!(user)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def destroy
|
37
|
-
authorize! :destroy, user
|
38
|
-
user.destroy
|
39
|
-
respond_with(user, :status => 204)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def user
|
45
|
-
@user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
|
46
|
-
end
|
47
|
-
|
48
|
-
def user_params
|
49
|
-
params.require(:user).permit(permitted_user_attributes |
|
50
|
-
[bill_address_attributes: permitted_address_attributes,
|
51
|
-
ship_address_attributes: permitted_address_attributes])
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class VariantsController < Spree::Api::BaseController
|
4
|
-
before_action :product
|
5
|
-
|
6
|
-
def create
|
7
|
-
authorize! :create, Spree::Variant
|
8
|
-
@variant = scope.new(variant_params)
|
9
|
-
if @variant.save
|
10
|
-
respond_with(@variant, status: 201, default_template: :show)
|
11
|
-
else
|
12
|
-
invalid_resource!(@variant)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def destroy
|
17
|
-
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
18
|
-
@variant.destroy
|
19
|
-
respond_with(@variant, status: 204)
|
20
|
-
end
|
21
|
-
|
22
|
-
# The lazyloaded associations here are pretty much attached to which nodes
|
23
|
-
# we render on the view so we better update it any time a node is included
|
24
|
-
# or removed from the views.
|
25
|
-
def index
|
26
|
-
@variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
|
27
|
-
.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
28
|
-
respond_with(@variants)
|
29
|
-
end
|
30
|
-
|
31
|
-
def new
|
32
|
-
end
|
33
|
-
|
34
|
-
def show
|
35
|
-
@variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
|
36
|
-
.find(params[:id])
|
37
|
-
respond_with(@variant)
|
38
|
-
end
|
39
|
-
|
40
|
-
def update
|
41
|
-
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
42
|
-
if @variant.update_attributes(variant_params)
|
43
|
-
respond_with(@variant, status: 200, default_template: :show)
|
44
|
-
else
|
45
|
-
invalid_resource!(@product)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
def product
|
51
|
-
@product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
|
52
|
-
end
|
53
|
-
|
54
|
-
def scope
|
55
|
-
if @product
|
56
|
-
variants = @product.variants_including_master
|
57
|
-
else
|
58
|
-
variants = Spree::Variant
|
59
|
-
end
|
60
|
-
|
61
|
-
if current_ability.can?(:manage, Spree::Variant) && params[:show_deleted]
|
62
|
-
variants = variants.with_deleted
|
63
|
-
end
|
64
|
-
|
65
|
-
variants.accessible_by(current_ability, :read)
|
66
|
-
end
|
67
|
-
|
68
|
-
def variant_params
|
69
|
-
params.require(:variant).permit(permitted_variant_attributes)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
module Api
|
3
|
-
class ZonesController < Spree::Api::BaseController
|
4
|
-
|
5
|
-
def create
|
6
|
-
authorize! :create, Spree::Zone
|
7
|
-
@zone = Spree::Zone.new(map_nested_attributes_keys(Spree::Zone, zone_params))
|
8
|
-
if @zone.save
|
9
|
-
respond_with(@zone, :status => 201, :default_template => :show)
|
10
|
-
else
|
11
|
-
invalid_resource!(@zone)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def destroy
|
16
|
-
authorize! :destroy, zone
|
17
|
-
zone.destroy
|
18
|
-
respond_with(zone, :status => 204)
|
19
|
-
end
|
20
|
-
|
21
|
-
def index
|
22
|
-
@zones = Spree::Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
23
|
-
respond_with(@zones)
|
24
|
-
end
|
25
|
-
|
26
|
-
def show
|
27
|
-
respond_with(zone)
|
28
|
-
end
|
29
|
-
|
30
|
-
def update
|
31
|
-
authorize! :update, zone
|
32
|
-
if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, zone_params))
|
33
|
-
respond_with(zone, :status => 200, :default_template => :show)
|
34
|
-
else
|
35
|
-
invalid_resource!(zone)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
def zone_params
|
41
|
-
params.require(:zone).permit!
|
42
|
-
end
|
43
|
-
|
44
|
-
def zone
|
45
|
-
@zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|