summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-01 13:15:14 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-01 13:15:14 -0600
commit283a368edd5d5c13aa8653156dd601505326864e (patch)
tree44606666ace5cbf4bf5b6c54e52d24209f18949e /app
parentd8842d83862fc26de22b3a6ed0a89e56f87b2e7e (diff)
Corregidos errores de ProductReviewsSerializer
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/reviews_controller.rb54
-rw-r--r--app/serializers/product_review_serializer.rb (renamed from app/serializers/product_reviews_serializer.rb)2
2 files changed, 29 insertions, 27 deletions
diff --git a/app/controllers/api/reviews_controller.rb b/app/controllers/api/reviews_controller.rb
index 8a5de64..353e382 100644
--- a/app/controllers/api/reviews_controller.rb
+++ b/app/controllers/api/reviews_controller.rb
@@ -1,41 +1,43 @@
# frozen_string_literal: true
-# ReviewController
-class ReviewsController < AuthenticatedController
- skip_before_action only: [:index]
+module Api
+ # ReviewsController
+ class ReviewsController < AuthenticatedController
+ skip_before_action :validate_jwt, only: :index
- def index
- @product = Product.find_by(public_id: params[:product_id])
+ def index
+ @product = Product.find_by(public_id: params[:product_id])
- render status: :not_found if @product.nil?
+ render status: :not_found and return if @product.nil?
- @reviews = @product.product_reviews.joins(:user_account).select('product_reviews.*',
+ @reviews = @product.product_reviews.joins(:user_account).select('product_reviews.*',
'user_accounts.first_name as author_name')
- render json: serialized_collection.serializable_hash, status: :ok
- end
+ render json: serialized_collection.serializable_hash, status: :ok
+ end
- def create
- @review = Review.new(permitted_params.merge({ product_id: params[:product_id],
- user_account_id: current_user_account.id }))
+ def create
+ @review = Review.new(permitted_params.merge({ product_id: params[:product_id],
+ user_account_id: current_user_account.id }))
- if @review.save
- render json: serialized_object.serializable_hash, status: :ok
- else
- render json: { error_messages: @review.errors.full_messages }, status: :unprocessable_entity
+ if @review.save
+ render json: serialized_object.serializable_hash, status: :ok
+ else
+ render json: { error_messages: @review.errors.full_messages }, status: :unprocessable_entity
+ end
end
- end
- private
+ private
- def permitted_params
- params.permit(:review, :rating)
- end
+ def permitted_params
+ params.permit(:review, :rating)
+ end
- def serialized_collection
- @serialized_collection ||= ProductReviewSerializer.new(@reviews)
- end
+ def serialized_collection
+ @serialized_collection ||= ProductReviewSerializer.new(@reviews)
+ end
- def serialized_object
- @serialized_object ||= ProductReviewSerializer.new(@review)
+ def serialized_object
+ @serialized_object ||= ProductReviewSerializer.new(@review)
+ end
end
end
diff --git a/app/serializers/product_reviews_serializer.rb b/app/serializers/product_review_serializer.rb
index 9a48f56..1400d2e 100644
--- a/app/serializers/product_reviews_serializer.rb
+++ b/app/serializers/product_review_serializer.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
# ProductReviewSerializer
-class ProductReviews < BaseSerializer
+class ProductReviewSerializer < BaseSerializer
attributes :review, :rating, :author_name
end