Skip to content

Commit

Permalink
Remove ApplicationService
Browse files Browse the repository at this point in the history
  • Loading branch information
marlena-b committed Sep 18, 2024
1 parent 3e990b5 commit 2737173
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def new
end

def create
Client::Orders::SubmitService.new(order_id: params[:order_id], customer_id: cookies[:client_id]).call
Client::Orders::SubmitService.call(order_id: params[:order_id], customer_id: cookies[:client_id])
rescue Orders::OrderHasUnavailableProducts => e
unavailable_products = e.unavailable_products.join(", ")
redirect_to edit_client_order_path(params[:order_id]), alert: "Order can not be submitted! #{unavailable_products} not available in requested quantity!"
Expand Down
2 changes: 1 addition & 1 deletion rails_application/app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def remove_item
end

def create
Orders::SubmitService.new(order_id: params[:order_id], customer_id: params[:customer_id]).call
Orders::SubmitService.call(order_id: params[:order_id], customer_id: params[:customer_id])
rescue Orders::OrderHasUnavailableProducts => e
unavailable_products = e.unavailable_products.join(", ")
redirect_to edit_order_path(params[:order_id]), alert: "Order can not be submitted! #{unavailable_products} not available in requested quantity!"
Expand Down
17 changes: 0 additions & 17 deletions rails_application/app/services/application_service.rb

This file was deleted.

14 changes: 13 additions & 1 deletion rails_application/app/services/client/orders/submit_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ def initialize(unavailable_products)
end
end

class SubmitService < ApplicationService
class SubmitService
def self.call(...)
new(...).call
end

def initialize(order_id:, customer_id:)
@order_id = order_id
@customer_id = customer_id
Expand Down Expand Up @@ -38,6 +42,14 @@ def submit_order
command_bus.(Crm::AssignCustomerToOrder.new(order_id: order_id, customer_id: customer_id))
end
end

def event_store
Rails.configuration.event_store
end

def command_bus
Rails.configuration.command_bus
end
end
end
end
14 changes: 13 additions & 1 deletion rails_application/app/services/orders/submit_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ def initialize(unavailable_products)
end
end

class SubmitService < ApplicationService
class SubmitService
def self.call(...)
new(...).call
end

def initialize(order_id:, customer_id:)
@order_id = order_id
@customer_id = customer_id
Expand Down Expand Up @@ -37,5 +41,13 @@ def submit_order
command_bus.(Crm::AssignCustomerToOrder.new(order_id: order_id, customer_id: customer_id))
end
end

def event_store
Rails.configuration.event_store
end

def command_bus
Rails.configuration.command_bus
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_successful_order_submission
prepare_product(product_id, "Async Remote", 49)
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))

Client::Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call
Client::Orders::SubmitService.call(order_id: order_id, customer_id: customer_id)

order = ClientOrders::Order.find_by!(order_uid: order_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_successful_order_submission
prepare_product(product_id, "Async Remote", 49)
run_command(Ordering::AddItemToBasket.new(order_id: order_id, product_id: product_id))

Orders::SubmitService.new(order_id: order_id, customer_id: customer_id).call
Orders::SubmitService.call(order_id: order_id, customer_id: customer_id)

order = Order.find_by!(uid: order_id)

Expand Down

0 comments on commit 2737173

Please sign in to comment.