Sha256: 14a7b2e4dc6417abf0d6965219ae0bfc7a8d42e3b7b224493d80c985b7148d4f

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

module Spree
  module Api
    module V1
      class ProductsController < Spree::Api::V1::BaseController
        def index
          @products = product_scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
        end

        def show
          @product = find_product(params[:id])
        end

        def new
        end

        def create
          authorize! :create, Product
          params[:product][:available_on] ||= Time.now
          @product = Product.new(params[:product])
          if @product.save
            render :show, :status => 201
          else
            invalid_resource!(@product)
          end
        end

        def update
          authorize! :update, Product
          @product = find_product(params[:id])
          if @product.update_attributes(params[:product])
            render :show, :status => 200
          else
            invalid_resource!(@product)
          end
        end

        def destroy
          authorize! :delete, Product
          @product = find_product(params[:id])
          @product.update_attribute(:deleted_at, Time.now)
          @product.variants_including_master.update_all(:deleted_at => Time.now)
          render :text => nil, :status => 204
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
spree_api-1.2.5 app/controllers/spree/api/v1/products_controller.rb
spree_api-1.2.4 app/controllers/spree/api/v1/products_controller.rb
spree_api-1.2.3 app/controllers/spree/api/v1/products_controller.rb
spree_api-1.2.2 app/controllers/spree/api/v1/products_controller.rb