-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grouped rendering classes (all in arbre now) grouped product and order handlers bigger handlers (items) left as separate files
- Loading branch information
1 parent
314a425
commit fcc771d
Showing
20 changed files
with
127 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
rails_application/app/read_models/client_orders/assign_customer_to_order.rb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/cancel_order.rb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/change_product_name.rb
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
rails_application/app/read_models/client_orders/change_product_price.rb
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
rails_application/app/read_models/client_orders/configuration.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/confirm_order.rb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/expire_order.rb
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
rails_application/app/read_models/client_orders/order_handlers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module ClientOrders | ||
|
||
class ConfirmOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Paid" | ||
order.save! | ||
end | ||
end | ||
|
||
class SubmitOrder | ||
def call(event) | ||
order = Order.find_or_create_by(order_uid: event.data.fetch(:order_id)) | ||
order.number = event.data.fetch(:order_number) | ||
order.state = "Submitted" | ||
order.save! | ||
end | ||
end | ||
|
||
class UpdateDiscount | ||
def call(event) | ||
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id)) | ||
order.percentage_discount = event.data.fetch(:amount) | ||
order.save! | ||
end | ||
end | ||
|
||
class UpdateOrderTotalValue | ||
def call(event) | ||
order = Order.find_or_create_by!(order_uid: event.data.fetch(:order_id)) { |order| order.state = "Draft" } | ||
order.discounted_value = event.data.fetch(:discounted_amount) | ||
order.total_value = event.data.fetch(:total_amount) | ||
order.save! | ||
end | ||
end | ||
|
||
class UpdatePaidOrdersSummary | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
client = Client.where(uid: order.client_uid).first | ||
client.update(paid_orders_summary: client.paid_orders_summary + order.discounted_value) | ||
end | ||
end | ||
|
||
class ExpireOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Expired" | ||
order.save! | ||
end | ||
end | ||
|
||
class CancelOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Cancelled" | ||
order.save! | ||
end | ||
end | ||
|
||
class AssignCustomerToOrder | ||
def call(event) | ||
order_uid = event.data.fetch(:order_id) | ||
order = Order.find_by(order_uid: order_uid) | ||
|
||
if order.nil? | ||
order = Order.create!(order_uid: order_uid, state: "Draft") | ||
end | ||
|
||
order.client_uid = event.data.fetch(:customer_id) | ||
order.save! | ||
end | ||
end | ||
|
||
class ResetDiscount | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.percentage_discount = nil | ||
order.save! | ||
end | ||
end | ||
end |
30 changes: 30 additions & 0 deletions
30
rails_application/app/read_models/client_orders/product_handlers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module ClientOrders | ||
class RegisterProduct | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)) | ||
end | ||
end | ||
|
||
class ChangeProductName | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update( | ||
name: event.data.fetch(:name) | ||
) | ||
end | ||
end | ||
|
||
class ChangeProductPrice | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(price: event.data.fetch(:price)) | ||
end | ||
end | ||
|
||
class UpdateProductAvailability | ||
def call(event) | ||
product = Product.find_by(uid: event.data.fetch(:product_id)) | ||
available = event.data.fetch(:available) | ||
|
||
product.update(available: available.positive?) | ||
end | ||
end | ||
end |
7 changes: 0 additions & 7 deletions
7
rails_application/app/read_models/client_orders/register_product.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
rails_application/app/read_models/client_orders/reset_discount.rb
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
rails_application/app/read_models/client_orders/submit_order.rb
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
rails_application/app/read_models/client_orders/update_discount.rb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/update_order_total_value.rb
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
rails_application/app/read_models/client_orders/update_paid_orders_summary.rb
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
rails_application/app/read_models/client_orders/update_product_availability.rb
This file was deleted.
Oops, something went wrong.