spree/spree

Spree::Api::V1::ImagesController
C

Similar code found in 1 other location

module Spree
  module Api
    module V1
      class ImagesController < Spree::Api::BaseController
        def index
api/app/controllers/spree/api/v1/return_authorizations_controller.rb on lines 40..45

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

module Spree
  module Api
    module V1
      class ImagesController < Spree::Api::BaseController
        def index
api/app/controllers/spree/api/v1/return_authorizations_controller.rb on lines 6..12

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

Similar code found in 1 other location

module Spree
  module Api
    module V1
      class ImagesController < Spree::Api::BaseController
        def index
api/app/controllers/spree/api/v1/return_authorizations_controller.rb on lines 16..19

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Refactorings

Further Reading

There are no issues that match your filters.

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

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

        def new
        end

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

        def update
          @image = scope.images.accessible_by(current_ability, :update).find(params[:id])
          if @image.update_attributes(image_params)
            respond_with(@image, default_template: :show)
          else
            invalid_resource!(@image)
          end
        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
end