mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
20 lines
659 B
Ruby
20 lines
659 B
Ruby
module Api
|
|
class ProductImagesController < Api::BaseController
|
|
respond_to :json
|
|
|
|
def update_product_image
|
|
@product = Spree::Product.find(params[:product_id])
|
|
authorize! :update, @product
|
|
|
|
if @product.images.first.nil?
|
|
@image = Spree::Image.create(attachment: params[:file], viewable_id: @product.master.id, viewable_type: 'Spree::Variant')
|
|
render json: @image, serializer: ImageSerializer, status: :created
|
|
else
|
|
@image = @product.images.first
|
|
@image.update_attributes(attachment: params[:file])
|
|
render json: @image, serializer: ImageSerializer, status: :ok
|
|
end
|
|
end
|
|
end
|
|
end
|