Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ApplicationService #401

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading