summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/products_controller.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/controllers/api/products_controller.rb b/app/controllers/api/products_controller.rb
index 2822a21..ec82af6 100644
--- a/app/controllers/api/products_controller.rb
+++ b/app/controllers/api/products_controller.rb
@@ -6,7 +6,7 @@ module Api
def show
@product = Product.find_by(public_id: params[:id])
- render json: { error_message: 'No existe el producto' }, status: :not_found and return if @product.nil?
+ render json: not_found_error_message, status: :not_found and return if @product.nil?
render json: serialized_object.serializable_hash, status: :ok
end
@@ -23,7 +23,7 @@ module Api
if @product.save
render json: serialized_object.serializable_hash, status: :ok
else
- render json: @product.errors.full_messages, status: :unprocessable_entity
+ render json: { error_messages: @product.errors.full_messages }, status: :unprocessable_entity
end
end
@@ -33,14 +33,14 @@ module Api
if @product.update(object_params)
render json: serialized_object.serializable_hash, status: :ok
else
- render json: @product.errors.full_messages, status: :unprocessable_entity
+ render json: { error_messages: @product.errors.full_messages }, status: :unprocessable_entity
end
end
def destroy
@product = Product.find_by(public_id: params[:id])
- render json: { error_message: 'No existe el producto' }, status: :not_found and return if @product.nil?
+ render json: not_found_error_message, status: :not_found and return if @product.nil?
@product.destroy
render status: :see_other
@@ -71,5 +71,9 @@ module Api
categories = permitted_params[:categories].split(',')
permitted_params.merge(categories:, public_id: SecureRandom.hex(12))
end
+
+ def not_found_error_message
+ { error_message: 'No existe el producto' }
+ end
end
end