diff --git a/rails_application/app/controllers/client/orders_controller.rb b/rails_application/app/controllers/client/orders_controller.rb index ffc59a5b..9c77be9e 100644 --- a/rails_application/app/controllers/client/orders_controller.rb +++ b/rails_application/app/controllers/client/orders_controller.rb @@ -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!" diff --git a/rails_application/app/controllers/orders_controller.rb b/rails_application/app/controllers/orders_controller.rb index ad926c5d..76bc55bc 100644 --- a/rails_application/app/controllers/orders_controller.rb +++ b/rails_application/app/controllers/orders_controller.rb @@ -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!" diff --git a/rails_application/app/services/application_service.rb b/rails_application/app/services/application_service.rb deleted file mode 100644 index 73f75e10..00000000 --- a/rails_application/app/services/application_service.rb +++ /dev/null @@ -1,17 +0,0 @@ -class ApplicationService - def self.call(...) - new(...).call - end - - def call - raise NotImplementedError - end - - def event_store - Rails.configuration.event_store - end - - def command_bus - Rails.configuration.command_bus - end -end diff --git a/rails_application/app/services/client/orders/submit_service.rb b/rails_application/app/services/client/orders/submit_service.rb index 3def1ce2..63301fba 100644 --- a/rails_application/app/services/client/orders/submit_service.rb +++ b/rails_application/app/services/client/orders/submit_service.rb @@ -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 @@ -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 diff --git a/rails_application/app/services/orders/submit_service.rb b/rails_application/app/services/orders/submit_service.rb index 84c6889c..31f473c2 100644 --- a/rails_application/app/services/orders/submit_service.rb +++ b/rails_application/app/services/orders/submit_service.rb @@ -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 @@ -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 diff --git a/rails_application/test/services/client/orders/submit_service_test.rb b/rails_application/test/services/client/orders/submit_service_test.rb index 412351d2..db93f4f5 100644 --- a/rails_application/test/services/client/orders/submit_service_test.rb +++ b/rails_application/test/services/client/orders/submit_service_test.rb @@ -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) diff --git a/rails_application/test/services/orders/submit_service_test.rb b/rails_application/test/services/orders/submit_service_test.rb index 3c0048fd..b3286a53 100644 --- a/rails_application/test/services/orders/submit_service_test.rb +++ b/rails_application/test/services/orders/submit_service_test.rb @@ -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)