Remove Spree module declaration from these files as they were moved out of the spree namespace

This commit is contained in:
luisramos0
2019-08-01 14:30:11 +01:00
parent 31bac9641f
commit aa3c1aa0fe
4 changed files with 500 additions and 508 deletions

View File

@@ -1,81 +1,79 @@
module Spree
module Api
class VariantsController < ::Api::BaseController
respond_to :json
module Api
class VariantsController < ::Api::BaseController
respond_to :json
skip_authorization_check only: [:index, :show]
before_filter :product
skip_authorization_check only: [:index, :show]
before_filter :product
def index
@variants = scope.includes(:option_values).ransack(params[:q]).result
render json: @variants, each_serializer: ::Api::VariantSerializer
def index
@variants = scope.includes(:option_values).ransack(params[:q]).result
render json: @variants, each_serializer: ::Api::VariantSerializer
end
def show
@variant = scope.includes(:option_values).find(params[:id])
render json: @variant, serializer: ::Api::VariantSerializer
end
def create
authorize! :create, Variant
@variant = scope.new(params[:variant])
if @variant.save
render json: @variant, serializer: ::Api::VariantSerializer, status: 201
else
invalid_resource!(@variant)
end
end
def show
@variant = scope.includes(:option_values).find(params[:id])
render json: @variant, serializer: ::Api::VariantSerializer
def update
authorize! :update, Variant
@variant = scope.find(params[:id])
if @variant.update_attributes(params[:variant])
render json: @variant, serializer: ::Api::VariantSerializer, status: 200
else
invalid_resource!(@product)
end
end
def create
authorize! :create, Variant
@variant = scope.new(params[:variant])
if @variant.save
render json: @variant, serializer: ::Api::VariantSerializer, status: 201
def soft_delete
@variant = scope.find(params[:variant_id])
authorize! :delete, @variant
VariantDeleter.new.delete(@variant)
render json: @variant, serializer: ::Api::VariantSerializer, status: 204
end
def destroy
authorize! :delete, Variant
@variant = scope.find(params[:id])
@variant.destroy
render json: @variant, serializer: ::Api::VariantSerializer, status: 204
end
private
def product
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
end
def scope
if @product
unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
variants = @product.variants_including_master
else
invalid_resource!(@variant)
variants = @product.variants_including_master.with_deleted
end
end
def update
authorize! :update, Variant
@variant = scope.find(params[:id])
if @variant.update_attributes(params[:variant])
render json: @variant, serializer: ::Api::VariantSerializer, status: 200
else
invalid_resource!(@product)
end
end
def soft_delete
@variant = scope.find(params[:variant_id])
authorize! :delete, @variant
VariantDeleter.new.delete(@variant)
render json: @variant, serializer: ::Api::VariantSerializer, status: 204
end
def destroy
authorize! :delete, Variant
@variant = scope.find(params[:id])
@variant.destroy
render json: @variant, serializer: ::Api::VariantSerializer, status: 204
end
private
def product
@product ||= Spree::Product.find_by_permalink(params[:product_id]) if params[:product_id]
end
def scope
if @product
unless current_api_user.has_spree_role?("admin") || params[:show_deleted]
variants = @product.variants_including_master
else
variants = @product.variants_including_master.with_deleted
else
variants = Variant.scoped
if current_api_user.has_spree_role?("admin")
unless params[:show_deleted]
variants = Variant.active
end
else
variants = Variant.scoped
if current_api_user.has_spree_role?("admin")
unless params[:show_deleted]
variants = Variant.active
end
else
variants = variants.active
end
variants = variants.active
end
variants
end
variants
end
end
end