summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-03-16 22:36:37 -0600
committerHombreLaser <sebastian-440@live.com>2023-03-16 22:36:37 -0600
commit717fa996842012a8666bcff985218c2abddd9991 (patch)
tree1a37cc6c2684aad20c093f43086c7674d17e7e4f /app/controllers/api
parentf68124a6dff2b0b6131280be2378a049d9d839d4 (diff)
Mejora ProductsController
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