Sha256: a4c3a88edf7ee2916669386ca36b34a52efff57c527f46e12bacb45cb91c5126
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
module Spree module Api class ProductsController < Spree::Api::BaseController respond_to :json def index if params[:ids] @products = product_scope.where(:id => params[:ids]) else @products = product_scope.ransack(params[:q]).result end @products = @products.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
5 entries across 5 versions & 1 rubygems