Sha256: a18dcd13a9ae8485ae318af1f7a3990fffc328944e035021e353f2f7cf04111a
Contents?: true
Size: 1.31 KB
Versions: 6
Compression:
Stored size: 1.31 KB
Contents
module Spree module Api class ProductsController < Spree::Api::BaseController respond_to :json def index @products = product_scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page]) respond_with(@products) end def show @product = find_product(params[:id]) respond_with(@product) end def new end def create authorize! :create, Product params[:product][:available_on] ||= Time.now @product = Product.new(params[:product]) if @product.save respond_with(@product, :status => 201, :default_template => :show) else invalid_resource!(@product) end end def update authorize! :update, Product @product = find_product(params[:id]) if @product.update_attributes(params[:product]) respond_with(@product, :status => 200, :default_template => :show) 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) respond_with(@product, :status => 204) end end end end
Version data entries
6 entries across 6 versions & 2 rubygems