mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
add checkout controller and refactoring cart controller
This commit is contained in:
parent
73a2e328a5
commit
5ec541d854
@ -2,6 +2,8 @@
|
||||
|
||||
# API Controller for manage user's cart
|
||||
class API::CartController < API::ApiController
|
||||
include API::OrderConcern
|
||||
|
||||
before_action :current_order, except: %i[create]
|
||||
before_action :ensure_order, except: %i[create]
|
||||
|
||||
@ -37,18 +39,6 @@ class API::CartController < API::ApiController
|
||||
|
||||
private
|
||||
|
||||
def order_token
|
||||
request.headers['X-Fablab-Order-Token'] || cart_params[:order_token]
|
||||
end
|
||||
|
||||
def current_order
|
||||
@current_order = Order.find_by(token: order_token)
|
||||
end
|
||||
|
||||
def ensure_order
|
||||
raise ActiveRecord::RecordNotFound if @current_order.nil?
|
||||
end
|
||||
|
||||
def orderable
|
||||
Product.find(cart_params[:orderable_id])
|
||||
end
|
||||
|
6
app/controllers/api/checkout_controller.rb
Normal file
6
app/controllers/api/checkout_controller.rb
Normal file
@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# API Controller for cart checkout
|
||||
class API::CheckoutController < API::ApiController
|
||||
include ::API::OrderConcern
|
||||
end
|
18
app/controllers/concerns/api/order_concern.rb
Normal file
18
app/controllers/concerns/api/order_concern.rb
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Concern for CartController and CheckoutController
|
||||
module API::OrderConcern
|
||||
private
|
||||
|
||||
def order_token
|
||||
request.headers['X-Fablab-Order-Token'] || cart_params[:order_token]
|
||||
end
|
||||
|
||||
def current_order
|
||||
@current_order = Order.find_by(token: order_token)
|
||||
end
|
||||
|
||||
def ensure_order
|
||||
raise ActiveRecord::RecordNotFound if @current_order.nil?
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user