Class: Spree::Api::ReviewsController
- Inherits:
-
BaseController
- Object
- BaseController
- Spree::Api::ReviewsController
- Defined in:
- lib/controllers/spree/api/reviews_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/controllers/spree/api/reviews_controller.rb', line 28 def create return not_found if @product.nil? @review = Spree::Review.new(review_params) @review.product = @product @review.user = @current_api_user @review.ip_address = request.remote_ip @review.locale = I18n.locale.to_s if Spree::Reviews::Config[:track_locale] :create, @review if @review.save render json: @review, include: [:images, :feedback_reviews], status: :created else invalid_resource!(@review) end end |
#destroy ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/controllers/spree/api/reviews_controller.rb', line 57 def destroy :destroy, @review if @review.destroy render json: @review, status: :ok else invalid_resource!(@review) end end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/controllers/spree/api/reviews_controller.rb', line 13 def index @reviews = if @product Spree::Review.default_approval_filter.where(product: @product) else Spree::Review.where(user: @current_api_user) end respond_with(@reviews) end |
#show ⇒ Object
23 24 25 26 |
# File 'lib/controllers/spree/api/reviews_controller.rb', line 23 def show :read, @review render json: @review, include: [:images, :feedback_reviews] end |
#update ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/controllers/spree/api/reviews_controller.rb', line 45 def update :update, @review attributes = review_params.merge(ip_address: request.remote_ip, approved: false) if @review.update(attributes) render json: @review, include: [:images, :feedback_reviews], status: :ok else invalid_resource!(@review) end end |