Sha256: 2e5f7fd19e7d9ae8a5af9296d96246e3475db6dcee659ec809d23afaae378f25

Contents?: true

Size: 1.27 KB

Versions: 81

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Spree
  module Api
    class ImagesController < Spree::Api::BaseController
      def index
        @images = scope.images.accessible_by(current_ability)
        respond_with(@images)
      end

      def show
        @image = scope.images.accessible_by(current_ability, :show).find(params[:id])
        respond_with(@image)
      end

      def create
        authorize! :create, Image
        @image = scope.images.create(image_params)
        respond_with(@image, status: 201, default_template: :show)
      end

      def update
        @image = scope.gallery.images.accessible_by(current_ability, :update).find(params[:id])
        @image.update(image_params)
        respond_with(@image, default_template: :show)
      end

      def destroy
        @image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])
        @image.destroy
        respond_with(@image, status: 204)
      end

      private

      def image_params
        params.require(:image).permit(permitted_image_attributes)
      end

      def scope
        if params[:product_id]
          Spree::Product.friendly.find(params[:product_id])
        elsif params[:variant_id]
          Spree::Variant.find(params[:variant_id])
        end
      end
    end
  end
end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
solidus_api-3.2.5 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.4 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.3 app/controllers/spree/api/images_controller.rb
solidus_api-3.1.8 app/controllers/spree/api/images_controller.rb
solidus_api-3.0.8 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.2 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.1 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.0 app/controllers/spree/api/images_controller.rb
solidus_api-3.2.0.alpha app/controllers/spree/api/images_controller.rb
solidus_api-3.0.7 app/controllers/spree/api/images_controller.rb
solidus_api-2.11.17 app/controllers/spree/api/images_controller.rb
solidus_api-3.1.7 app/controllers/spree/api/images_controller.rb
solidus_api-2.11.16 app/controllers/spree/api/images_controller.rb
solidus_api-3.0.6 app/controllers/spree/api/images_controller.rb
solidus_api-3.1.6 app/controllers/spree/api/images_controller.rb
solidus_api-2.11.15 app/controllers/spree/api/images_controller.rb
solidus_api-2.11.14 app/controllers/spree/api/images_controller.rb
solidus_api-3.0.5 app/controllers/spree/api/images_controller.rb
solidus_api-3.1.5 app/controllers/spree/api/images_controller.rb
solidus_api-2.11.13 app/controllers/spree/api/images_controller.rb