summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
authorHombreLaser <sebastian-440@live.com>2023-04-13 18:14:35 -0600
committerHombreLaser <sebastian-440@live.com>2023-04-13 18:14:35 -0600
commit4b0527efc4b7703c99043013fd455f496d32329c (patch)
tree7c3c3df32ecad6516474d61b0ed967436433f744 /app/controllers/api
parent4fa1f4ac81951f9b373d2167413ac3401fd8d060 (diff)
Añade OrdersController
Diffstat (limited to 'app/controllers/api')
-rw-r--r--app/controllers/api/orders_controller.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb
new file mode 100644
index 0000000..7a26d11
--- /dev/null
+++ b/app/controllers/api/orders_controller.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+module Api
+ # OrdersController
+ class OrdersController < AuthenticatedController
+ def index
+ @orders = current_user_account.orders
+
+ render json: serialized_collection.serializable_hash, status: :ok
+ end
+
+ def create
+ @service = PaymentService.new(@order, permitted_params[:card_id])
+ @order = @service.call
+
+ if @order
+ render json: serialized_object.serializable_hash, status: :ok
+ else
+ render json: { errors: @service.error_messages }, status: :unprocessable_entity
+ end
+ end
+
+ private
+
+ def serialized_collection
+ @serialized_collection ||= OrderSerializer.new(@orders)
+ end
+
+ def serialized_object
+ @serialized_object ||= OrderSerializer.new(@order)
+ end
+ end
+end