summaryrefslogtreecommitdiff
path: root/app/controllers/api
diff options
context:
space:
mode:
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