harpiya_api 4.3.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +5 -0
- data/LICENSE +26 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/harpiya/api/main.js +36 -0
- data/app/assets/javascripts/harpiya/api/storefront/cart.js +49 -0
- data/app/controllers/concerns/harpiya/api/v2/storefront/order_concern.rb +52 -0
- data/app/controllers/harpiya/api/base_controller.rb +171 -0
- data/app/controllers/harpiya/api/errors_controller.rb +9 -0
- data/app/controllers/harpiya/api/v1/addresses_controller.rb +46 -0
- data/app/controllers/harpiya/api/v1/checkouts_controller.rb +106 -0
- data/app/controllers/harpiya/api/v1/classifications_controller.rb +20 -0
- data/app/controllers/harpiya/api/v1/countries_controller.rb +22 -0
- data/app/controllers/harpiya/api/v1/credit_cards_controller.rb +26 -0
- data/app/controllers/harpiya/api/v1/customer_returns_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/images_controller.rb +58 -0
- data/app/controllers/harpiya/api/v1/inventory_units_controller.rb +54 -0
- data/app/controllers/harpiya/api/v1/line_items_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/option_types_controller.rb +60 -0
- data/app/controllers/harpiya/api/v1/option_values_controller.rb +62 -0
- data/app/controllers/harpiya/api/v1/orders_controller.rb +156 -0
- data/app/controllers/harpiya/api/v1/payments_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/product_properties_controller.rb +73 -0
- data/app/controllers/harpiya/api/v1/products_controller.rb +131 -0
- data/app/controllers/harpiya/api/v1/promotions_controller.rb +30 -0
- data/app/controllers/harpiya/api/v1/properties_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/reimbursements_controller.rb +25 -0
- data/app/controllers/harpiya/api/v1/return_authorizations_controller.rb +70 -0
- data/app/controllers/harpiya/api/v1/shipments_controller.rb +196 -0
- data/app/controllers/harpiya/api/v1/states_controller.rb +36 -0
- data/app/controllers/harpiya/api/v1/stock_items_controller.rb +82 -0
- data/app/controllers/harpiya/api/v1/stock_locations_controller.rb +53 -0
- data/app/controllers/harpiya/api/v1/stock_movements_controller.rb +45 -0
- data/app/controllers/harpiya/api/v1/stores_controller.rb +56 -0
- data/app/controllers/harpiya/api/v1/taxonomies_controller.rb +67 -0
- data/app/controllers/harpiya/api/v1/taxons_controller.rb +100 -0
- data/app/controllers/harpiya/api/v1/users_controller.rb +97 -0
- data/app/controllers/harpiya/api/v1/variants_controller.rb +81 -0
- data/app/controllers/harpiya/api/v1/zones_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/base_controller.rb +167 -0
- data/app/controllers/harpiya/api/v2/platform/addresses_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/countries_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/menu_items_controller.rb +35 -0
- data/app/controllers/harpiya/api/v2/platform/menus_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/option_types_controller.rb +15 -0
- data/app/controllers/harpiya/api/v2/platform/option_values_controller.rb +19 -0
- data/app/controllers/harpiya/api/v2/platform/products_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/resource_controller.rb +102 -0
- data/app/controllers/harpiya/api/v2/platform/taxons_controller.rb +27 -0
- data/app/controllers/harpiya/api/v2/platform/users_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/resource_controller.rb +59 -0
- data/app/controllers/harpiya/api/v2/storefront/account/addresses_controller.rb +75 -0
- data/app/controllers/harpiya/api/v2/storefront/account/credit_cards_controller.rb +39 -0
- data/app/controllers/harpiya/api/v2/storefront/account/orders_controller.rb +46 -0
- data/app/controllers/harpiya/api/v2/storefront/account_controller.rb +52 -0
- data/app/controllers/harpiya/api/v2/storefront/cart_controller.rb +195 -0
- data/app/controllers/harpiya/api/v2/storefront/checkout_controller.rb +136 -0
- data/app/controllers/harpiya/api/v2/storefront/countries_controller.rb +50 -0
- data/app/controllers/harpiya/api/v2/storefront/menus_controller.rb +42 -0
- data/app/controllers/harpiya/api/v2/storefront/order_status_controller.rb +34 -0
- data/app/controllers/harpiya/api/v2/storefront/products_controller.rb +55 -0
- data/app/controllers/harpiya/api/v2/storefront/stores_controller.rb +23 -0
- data/app/controllers/harpiya/api/v2/storefront/taxons_controller.rb +47 -0
- data/app/helpers/harpiya/api/api_helpers.rb +190 -0
- data/app/helpers/harpiya/api/v2/collection_options_helpers.rb +46 -0
- data/app/helpers/harpiya/api/v2/display_money_helper.rb +43 -0
- data/app/models/concerns/harpiya/user_api_authentication.rb +19 -0
- data/app/models/concerns/harpiya/user_api_methods.rb +7 -0
- data/app/models/harpiya/api_configuration.rb +8 -0
- data/app/models/harpiya/api_dependencies.rb +98 -0
- data/app/serializers/concerns/harpiya/api/v2/resource_serializer_concern.rb +16 -0
- data/app/serializers/harpiya/api/v2/base_serializer.rb +32 -0
- data/app/serializers/harpiya/api/v2/platform/address_serializer.rb +15 -0
- data/app/serializers/harpiya/api/v2/platform/base_serializer.rb +10 -0
- data/app/serializers/harpiya/api/v2/platform/country_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/menu_item_serializer.rb +22 -0
- data/app/serializers/harpiya/api/v2/platform/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/product_property_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/product_serializer.rb +28 -0
- data/app/serializers/harpiya/api/v2/platform/state_serializer.rb +13 -0
- data/app/serializers/harpiya/api/v2/platform/store_serializer.rb +14 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/taxon_serializer.rb +37 -0
- data/app/serializers/harpiya/api/v2/platform/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/api/v2/platform/user_serializer.rb +21 -0
- data/app/serializers/harpiya/api/v2/platform/variant_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/address_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/base_serializer.rb +10 -0
- data/app/serializers/harpiya/v2/storefront/cart_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/country_serializer.rb +24 -0
- data/app/serializers/harpiya/v2/storefront/credit_card_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/estimated_shipping_rate_serializer.rb +29 -0
- data/app/serializers/harpiya/v2/storefront/image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/line_item_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/menu_item_serializer.rb +38 -0
- data/app/serializers/harpiya/v2/storefront/menu_serializer.rb +14 -0
- data/app/serializers/harpiya/v2/storefront/option_type_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/option_value_serializer.rb +13 -0
- data/app/serializers/harpiya/v2/storefront/payment_method_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/payment_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/product_property_serializer.rb +19 -0
- data/app/serializers/harpiya/v2/storefront/product_serializer.rb +67 -0
- data/app/serializers/harpiya/v2/storefront/promotion_serializer.rb +12 -0
- data/app/serializers/harpiya/v2/storefront/shipment_serializer.rb +20 -0
- data/app/serializers/harpiya/v2/storefront/shipping_rate_serializer.rb +16 -0
- data/app/serializers/harpiya/v2/storefront/state_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/stock_location_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_category_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_event_serializer.rb +15 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_serializer.rb +17 -0
- data/app/serializers/harpiya/v2/storefront/store_credit_type_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/store_serializer.rb +23 -0
- data/app/serializers/harpiya/v2/storefront/taxon_image_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/taxon_serializer.rb +36 -0
- data/app/serializers/harpiya/v2/storefront/taxonomy_serializer.rb +11 -0
- data/app/serializers/harpiya/v2/storefront/user_serializer.rb +31 -0
- data/app/serializers/harpiya/v2/storefront/variant_serializer.rb +49 -0
- data/app/services/harpiya/api/error_handler.rb +40 -0
- data/app/views/harpiya/api/errors/gateway_error.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/invalid_resource.rabl +3 -0
- data/app/views/harpiya/api/errors/must_specify_api_key.rabl +2 -0
- data/app/views/harpiya/api/errors/not_found.rabl +2 -0
- data/app/views/harpiya/api/errors/unauthorized.rabl +2 -0
- data/app/views/harpiya/api/v1/addresses/show.rabl +10 -0
- data/app/views/harpiya/api/v1/adjustments/show.rabl +4 -0
- data/app/views/harpiya/api/v1/countries/index.rabl +7 -0
- data/app/views/harpiya/api/v1/countries/show.rabl +5 -0
- data/app/views/harpiya/api/v1/credit_cards/index.rabl +7 -0
- data/app/views/harpiya/api/v1/credit_cards/show.rabl +3 -0
- data/app/views/harpiya/api/v1/customer_returns/index.rabl +7 -0
- data/app/views/harpiya/api/v1/images/index.rabl +4 -0
- data/app/views/harpiya/api/v1/images/new.rabl +3 -0
- data/app/views/harpiya/api/v1/images/show.rabl +6 -0
- data/app/views/harpiya/api/v1/inventory_units/show.rabl +2 -0
- data/app/views/harpiya/api/v1/line_items/new.rabl +3 -0
- data/app/views/harpiya/api/v1/line_items/show.rabl +14 -0
- data/app/views/harpiya/api/v1/option_types/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_types/show.rabl +5 -0
- data/app/views/harpiya/api/v1/option_values/index.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/new.rabl +3 -0
- data/app/views/harpiya/api/v1/option_values/show.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/address.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/canceled.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/cart.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/complete.rabl +0 -0
- data/app/views/harpiya/api/v1/orders/could_not_apply_coupon.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/could_not_transition.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/index.rabl +7 -0
- data/app/views/harpiya/api/v1/orders/insufficient_quantity.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/invalid_shipping_method.rabl +2 -0
- data/app/views/harpiya/api/v1/orders/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/orders/order.rabl +10 -0
- data/app/views/harpiya/api/v1/orders/payment.rabl +3 -0
- data/app/views/harpiya/api/v1/orders/show.rabl +51 -0
- data/app/views/harpiya/api/v1/payments/credit_over_limit.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/index.rabl +7 -0
- data/app/views/harpiya/api/v1/payments/new.rabl +5 -0
- data/app/views/harpiya/api/v1/payments/show.rabl +2 -0
- data/app/views/harpiya/api/v1/payments/update_forbidden.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/product_properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/product_properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/products/index.rabl +9 -0
- data/app/views/harpiya/api/v1/products/new.rabl +3 -0
- data/app/views/harpiya/api/v1/products/product.rabl +1 -0
- data/app/views/harpiya/api/v1/products/show.rabl +36 -0
- data/app/views/harpiya/api/v1/promotions/handler.rabl +5 -0
- data/app/views/harpiya/api/v1/promotions/show.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/index.rabl +7 -0
- data/app/views/harpiya/api/v1/properties/new.rabl +2 -0
- data/app/views/harpiya/api/v1/properties/show.rabl +2 -0
- data/app/views/harpiya/api/v1/reimbursements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/return_authorizations/new.rabl +3 -0
- data/app/views/harpiya/api/v1/return_authorizations/show.rabl +2 -0
- data/app/views/harpiya/api/v1/shared/stock_location_required.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/big.rabl +48 -0
- data/app/views/harpiya/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
- data/app/views/harpiya/api/v1/shipments/mine.rabl +9 -0
- data/app/views/harpiya/api/v1/shipments/show.rabl +32 -0
- data/app/views/harpiya/api/v1/shipments/small.rabl +37 -0
- data/app/views/harpiya/api/v1/shipping_rates/show.rabl +2 -0
- data/app/views/harpiya/api/v1/states/index.rabl +12 -0
- data/app/views/harpiya/api/v1/states/show.rabl +2 -0
- data/app/views/harpiya/api/v1/stock_items/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_items/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stock_locations/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_locations/show.rabl +8 -0
- data/app/views/harpiya/api/v1/stock_movements/index.rabl +7 -0
- data/app/views/harpiya/api/v1/stock_movements/show.rabl +5 -0
- data/app/views/harpiya/api/v1/stores/index.rabl +4 -0
- data/app/views/harpiya/api/v1/stores/show.rabl +2 -0
- data/app/views/harpiya/api/v1/tags/index.rabl +9 -0
- data/app/views/harpiya/api/v1/taxonomies/index.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxonomies/nested.rabl +11 -0
- data/app/views/harpiya/api/v1/taxonomies/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxonomies/show.rabl +15 -0
- data/app/views/harpiya/api/v1/taxons/index.rabl +10 -0
- data/app/views/harpiya/api/v1/taxons/jstree.rabl +7 -0
- data/app/views/harpiya/api/v1/taxons/new.rabl +3 -0
- data/app/views/harpiya/api/v1/taxons/show.rabl +6 -0
- data/app/views/harpiya/api/v1/taxons/taxons.rabl +5 -0
- data/app/views/harpiya/api/v1/users/index.rabl +7 -0
- data/app/views/harpiya/api/v1/users/new.rabl +3 -0
- data/app/views/harpiya/api/v1/users/show.rabl +11 -0
- data/app/views/harpiya/api/v1/variants/big.rabl +14 -0
- data/app/views/harpiya/api/v1/variants/index.rabl +9 -0
- data/app/views/harpiya/api/v1/variants/new.rabl +2 -0
- data/app/views/harpiya/api/v1/variants/show.rabl +3 -0
- data/app/views/harpiya/api/v1/variants/small.rabl +18 -0
- data/app/views/harpiya/api/v1/zones/index.rabl +7 -0
- data/app/views/harpiya/api/v1/zones/show.rabl +6 -0
- data/config/initializers/doorkeeper.rb +48 -0
- data/config/initializers/json_api_mime_types.rb +8 -0
- data/config/initializers/rabl.rb +9 -0
- data/config/initializers/user_class_extensions.rb +7 -0
- data/config/locales/en.yml +36 -0
- data/config/routes.rb +295 -0
- data/db/migrate/20100107141738_add_api_key_to_harpiya_users.rb +7 -0
- data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
- data/db/migrate/20120530054546_rename_api_key_to_harpiya_api_key.rb +7 -0
- data/db/migrate/20131017162334_add_index_to_user_harpiya_api_key.rb +7 -0
- data/db/migrate/20180320110726_create_doorkeeper_tables.rb +69 -0
- data/docs/oauth/index.yml +140 -0
- data/docs/v2/platform/index.yaml +599 -0
- data/docs/v2/storefront/index.yaml +5585 -0
- data/harpiya_api.gemspec +36 -0
- data/lib/harpiya/api.rb +11 -0
- data/lib/harpiya/api/controller_setup.rb +19 -0
- data/lib/harpiya/api/engine.rb +30 -0
- data/lib/harpiya/api/responders.rb +11 -0
- data/lib/harpiya/api/responders/rabl_template.rb +28 -0
- data/lib/harpiya/api/testing_support/caching.rb +10 -0
- data/lib/harpiya/api/testing_support/helpers.rb +44 -0
- data/lib/harpiya/api/testing_support/setup.rb +16 -0
- data/lib/harpiya/api/testing_support/v2/base.rb +13 -0
- data/lib/harpiya/api/testing_support/v2/current_order.rb +79 -0
- data/lib/harpiya/api/testing_support/v2/platform_contexts.rb +213 -0
- data/lib/harpiya_api.rb +4 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- metadata +418 -0
@@ -0,0 +1,53 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StockLocationsController < Harpiya::Api::BaseController
|
5
|
+
def index
|
6
|
+
authorize! :index, StockLocation
|
7
|
+
@stock_locations = StockLocation.accessible_by(current_ability).order('name ASC').
|
8
|
+
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
9
|
+
respond_with(@stock_locations)
|
10
|
+
end
|
11
|
+
|
12
|
+
def show
|
13
|
+
respond_with(stock_location)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create
|
17
|
+
authorize! :create, StockLocation
|
18
|
+
@stock_location = StockLocation.new(stock_location_params)
|
19
|
+
if @stock_location.save
|
20
|
+
respond_with(@stock_location, status: 201, default_template: :show)
|
21
|
+
else
|
22
|
+
invalid_resource!(@stock_location)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def update
|
27
|
+
authorize! :update, stock_location
|
28
|
+
if stock_location.update(stock_location_params)
|
29
|
+
respond_with(stock_location, status: 200, default_template: :show)
|
30
|
+
else
|
31
|
+
invalid_resource!(stock_location)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
authorize! :destroy, stock_location
|
37
|
+
stock_location.destroy
|
38
|
+
respond_with(stock_location, status: 204)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def stock_location
|
44
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def stock_location_params
|
48
|
+
params.require(:stock_location).permit(permitted_stock_location_attributes)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StockMovementsController < Harpiya::Api::BaseController
|
5
|
+
before_action :stock_location, except: [:update, :destroy]
|
6
|
+
|
7
|
+
def index
|
8
|
+
authorize! :index, 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 'harpiya/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]
|
32
|
+
@stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])
|
33
|
+
end
|
34
|
+
|
35
|
+
def scope
|
36
|
+
@stock_location.stock_movements.accessible_by(current_ability, :show)
|
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,56 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class StoresController < Harpiya::Api::BaseController
|
5
|
+
before_action :get_store, except: [:index, :create]
|
6
|
+
|
7
|
+
def index
|
8
|
+
authorize! :index, Store
|
9
|
+
@stores = Store.accessible_by(current_ability).all
|
10
|
+
respond_with(@stores)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
authorize! :create, Store
|
15
|
+
@store = Store.new(store_params)
|
16
|
+
@store.code = params[:store][:code]
|
17
|
+
if @store.save
|
18
|
+
respond_with(@store, status: 201, default_template: :show)
|
19
|
+
else
|
20
|
+
invalid_resource!(@store)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
authorize! :update, @store
|
26
|
+
if @store.update(store_params)
|
27
|
+
respond_with(@store, status: 200, default_template: :show)
|
28
|
+
else
|
29
|
+
invalid_resource!(@store)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show
|
34
|
+
authorize! :show, @store
|
35
|
+
respond_with(@store)
|
36
|
+
end
|
37
|
+
|
38
|
+
def destroy
|
39
|
+
authorize! :destroy, @store
|
40
|
+
@store.destroy
|
41
|
+
respond_with(@store, status: 204)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def get_store
|
47
|
+
@store = Store.find(params[:id])
|
48
|
+
end
|
49
|
+
|
50
|
+
def store_params
|
51
|
+
params.require(:store).permit(permitted_store_attributes)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class TaxonomiesController < Harpiya::Api::BaseController
|
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 new; end
|
19
|
+
|
20
|
+
def create
|
21
|
+
authorize! :create, Taxonomy
|
22
|
+
@taxonomy = Taxonomy.new(taxonomy_params)
|
23
|
+
if @taxonomy.save
|
24
|
+
respond_with(@taxonomy, status: 201, default_template: :show)
|
25
|
+
else
|
26
|
+
invalid_resource!(@taxonomy)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def update
|
31
|
+
authorize! :update, taxonomy
|
32
|
+
if taxonomy.update(taxonomy_params)
|
33
|
+
respond_with(taxonomy, status: 200, default_template: :show)
|
34
|
+
else
|
35
|
+
invalid_resource!(taxonomy)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def destroy
|
40
|
+
authorize! :destroy, taxonomy
|
41
|
+
taxonomy.destroy
|
42
|
+
respond_with(taxonomy, status: 204)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def taxonomies
|
48
|
+
@taxonomies = Taxonomy.accessible_by(current_ability).order('name').includes(root: :children).
|
49
|
+
ransack(params[:q]).result.
|
50
|
+
page(params[:page]).per(params[:per_page])
|
51
|
+
end
|
52
|
+
|
53
|
+
def taxonomy
|
54
|
+
@taxonomy ||= Taxonomy.accessible_by(current_ability, :show).find(params[:id])
|
55
|
+
end
|
56
|
+
|
57
|
+
def taxonomy_params
|
58
|
+
if params[:taxonomy] && !params[:taxonomy].empty?
|
59
|
+
params.require(:taxonomy).permit(permitted_taxonomy_attributes)
|
60
|
+
else
|
61
|
+
{}
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class TaxonsController < Harpiya::Api::BaseController
|
5
|
+
def index
|
6
|
+
@taxons = if taxonomy
|
7
|
+
taxonomy.root.children
|
8
|
+
elsif params[:ids]
|
9
|
+
Harpiya::Taxon.includes(:children).accessible_by(current_ability).where(id: params[:ids].split(','))
|
10
|
+
else
|
11
|
+
Harpiya::Taxon.includes(:children).accessible_by(current_ability).order(:taxonomy_id, :lft)
|
12
|
+
end
|
13
|
+
@taxons = @taxons.ransack(params[:q]).result
|
14
|
+
@taxons = @taxons.page(params[:page]).per(params[:per_page])
|
15
|
+
respond_with(@taxons)
|
16
|
+
end
|
17
|
+
|
18
|
+
def show
|
19
|
+
@taxon = taxon
|
20
|
+
respond_with(@taxon)
|
21
|
+
end
|
22
|
+
|
23
|
+
def jstree
|
24
|
+
show
|
25
|
+
end
|
26
|
+
|
27
|
+
def new; end
|
28
|
+
|
29
|
+
def create
|
30
|
+
authorize! :create, Taxon
|
31
|
+
@taxon = Harpiya::Taxon.new(taxon_params)
|
32
|
+
@taxon.taxonomy_id = params[:taxonomy_id]
|
33
|
+
taxonomy = Harpiya::Taxonomy.find_by(id: params[:taxonomy_id])
|
34
|
+
|
35
|
+
if taxonomy.nil?
|
36
|
+
@taxon.errors.add(:taxonomy_id, I18n.t('harpiya.api.invalid_taxonomy_id'))
|
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(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 = Harpiya::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 'harpiya/api/v1/products/index'
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def taxonomy
|
76
|
+
if params[:taxonomy_id].present?
|
77
|
+
@taxonomy ||=
|
78
|
+
if defined?(HarpiyaGlobalize)
|
79
|
+
Harpiya::Taxonomy.includes(:translations, taxons: [:translations]).accessible_by(current_ability, :show).find(params[:taxonomy_id])
|
80
|
+
else
|
81
|
+
Harpiya::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def taxon
|
87
|
+
@taxon ||= taxonomy.taxons.accessible_by(current_ability, :show).find(params[:id])
|
88
|
+
end
|
89
|
+
|
90
|
+
def taxon_params
|
91
|
+
if params[:taxon] && !params[:taxon].empty?
|
92
|
+
params.require(:taxon).permit(permitted_taxon_attributes)
|
93
|
+
else
|
94
|
+
{}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class UsersController < Harpiya::Api::BaseController
|
5
|
+
rescue_from Harpiya::Core::DestroyWithOrdersError, with: :error_during_processing
|
6
|
+
|
7
|
+
def index
|
8
|
+
users
|
9
|
+
|
10
|
+
if params[:ids]
|
11
|
+
load_users_by_ids
|
12
|
+
elsif params.dig(:q, :ship_address_firstname_start)
|
13
|
+
load_users_by_address
|
14
|
+
elsif params.dig(:q, :email_start)
|
15
|
+
load_users_by_email
|
16
|
+
end
|
17
|
+
|
18
|
+
prepare_index_response
|
19
|
+
respond_with(@users)
|
20
|
+
end
|
21
|
+
|
22
|
+
def users
|
23
|
+
@users ||= Harpiya.user_class.accessible_by(current_ability, :show)
|
24
|
+
end
|
25
|
+
|
26
|
+
def load_users_by_ids
|
27
|
+
@users = @users.where(id: params[:ids])
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_users_by_address
|
31
|
+
address_params = params[:q][:ship_address_firstname_start] ||
|
32
|
+
params[:q][:ship_address_lastname_start] ||
|
33
|
+
params[:q][:bill_address_firstname_start] ||
|
34
|
+
params[:q][:bill_address_lastname_start]
|
35
|
+
@users = @users.with_email_or_address(params[:q][:email_start], address_params)
|
36
|
+
end
|
37
|
+
|
38
|
+
def load_users_by_email
|
39
|
+
@users = @users.with_email(params[:q][:email_start])
|
40
|
+
end
|
41
|
+
|
42
|
+
def paginate_users
|
43
|
+
@users = @users.page(params[:page]).per(params[:per_page])
|
44
|
+
end
|
45
|
+
|
46
|
+
def prepare_index_response
|
47
|
+
paginate_users
|
48
|
+
expires_in 15.minutes, public: true
|
49
|
+
headers['Surrogate-Control'] = "max-age=#{15.minutes}"
|
50
|
+
end
|
51
|
+
|
52
|
+
def show
|
53
|
+
respond_with(user)
|
54
|
+
end
|
55
|
+
|
56
|
+
def new; end
|
57
|
+
|
58
|
+
def create
|
59
|
+
authorize! :create, Harpiya.user_class
|
60
|
+
@user = Harpiya.user_class.new(user_params)
|
61
|
+
if @user.save
|
62
|
+
respond_with(@user, status: 201, default_template: :show)
|
63
|
+
else
|
64
|
+
invalid_resource!(@user)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def update
|
69
|
+
authorize! :update, user
|
70
|
+
if user.update(user_params)
|
71
|
+
respond_with(user, status: 200, default_template: :show)
|
72
|
+
else
|
73
|
+
invalid_resource!(user)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def destroy
|
78
|
+
authorize! :destroy, user
|
79
|
+
user.destroy
|
80
|
+
respond_with(user, status: 204)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def user
|
86
|
+
@user ||= Harpiya.user_class.accessible_by(current_ability, :show).find(params[:id])
|
87
|
+
end
|
88
|
+
|
89
|
+
def user_params
|
90
|
+
params.require(:user).permit(permitted_user_attributes |
|
91
|
+
[bill_address_attributes: permitted_address_attributes,
|
92
|
+
ship_address_attributes: permitted_address_attributes])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module Harpiya
|
2
|
+
module Api
|
3
|
+
module V1
|
4
|
+
class VariantsController < Harpiya::Api::BaseController
|
5
|
+
before_action :product
|
6
|
+
|
7
|
+
def create
|
8
|
+
authorize! :create, Variant
|
9
|
+
@variant = scope.new(variant_params)
|
10
|
+
if @variant.save
|
11
|
+
respond_with(@variant, status: 201, default_template: :show)
|
12
|
+
else
|
13
|
+
invalid_resource!(@variant)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def destroy
|
18
|
+
@variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
|
19
|
+
@variant.destroy
|
20
|
+
respond_with(@variant, status: 204)
|
21
|
+
end
|
22
|
+
|
23
|
+
# The lazyloaded associations here are pretty much attached to which nodes
|
24
|
+
# we render on the view so we better update it any time a node is included
|
25
|
+
# or removed from the views.
|
26
|
+
def index
|
27
|
+
@variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.
|
28
|
+
ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
|
29
|
+
respond_with(@variants)
|
30
|
+
end
|
31
|
+
|
32
|
+
def new; end
|
33
|
+
|
34
|
+
def show
|
35
|
+
@variant = scope.includes(*variant_includes).find(params[:id])
|
36
|
+
respond_with(@variant)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update
|
40
|
+
@variant = scope.accessible_by(current_ability, :update).find(params[:id])
|
41
|
+
if @variant.update(variant_params)
|
42
|
+
respond_with(@variant, status: 200, default_template: :show)
|
43
|
+
else
|
44
|
+
invalid_resource!(@product)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def product
|
51
|
+
if params[:product_id]
|
52
|
+
@product ||= Harpiya::Product.accessible_by(current_ability, :show).
|
53
|
+
friendly.find(params[:product_id])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def scope
|
58
|
+
variants = if @product
|
59
|
+
@product.variants_including_master
|
60
|
+
else
|
61
|
+
Variant
|
62
|
+
end
|
63
|
+
|
64
|
+
if current_ability.can?(:manage, Variant) && params[:show_deleted]
|
65
|
+
variants = variants.with_deleted
|
66
|
+
end
|
67
|
+
|
68
|
+
variants.eligible.accessible_by(current_ability)
|
69
|
+
end
|
70
|
+
|
71
|
+
def variant_params
|
72
|
+
params.require(:variant).permit(permitted_variant_attributes)
|
73
|
+
end
|
74
|
+
|
75
|
+
def variant_includes
|
76
|
+
[{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|