-
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.
Applied namespaces changes to zeitwerk/mutant/tests
- Loading branch information
1 parent
fcc771d
commit 52b05a7
Showing
10 changed files
with
333 additions
and
324 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
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
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
121 changes: 61 additions & 60 deletions
121
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 |
---|---|---|
@@ -1,82 +1,83 @@ | ||
module ClientOrders | ||
|
||
class ConfirmOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Paid" | ||
order.save! | ||
module OrderHandlers | ||
class ConfirmOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Paid" | ||
order.save! | ||
end | ||
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! | ||
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 | ||
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! | ||
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 | ||
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! | ||
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 | ||
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) | ||
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 | ||
end | ||
|
||
class ExpireOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Expired" | ||
order.save! | ||
class ExpireOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Expired" | ||
order.save! | ||
end | ||
end | ||
end | ||
|
||
class CancelOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Cancelled" | ||
order.save! | ||
class CancelOrder | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.state = "Cancelled" | ||
order.save! | ||
end | ||
end | ||
end | ||
|
||
class AssignCustomerToOrder | ||
def call(event) | ||
order_uid = event.data.fetch(:order_id) | ||
order = Order.find_by(order_uid: order_uid) | ||
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 | ||
if order.nil? | ||
order = Order.create!(order_uid: order_uid, state: "Draft") | ||
end | ||
|
||
order.client_uid = event.data.fetch(:customer_id) | ||
order.save! | ||
order.client_uid = event.data.fetch(:customer_id) | ||
order.save! | ||
end | ||
end | ||
end | ||
|
||
class ResetDiscount | ||
def call(event) | ||
order = Order.find_by(order_uid: event.data.fetch(:order_id)) | ||
order.percentage_discount = nil | ||
order.save! | ||
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 | ||
end |
40 changes: 21 additions & 19 deletions
40
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 |
---|---|---|
@@ -1,30 +1,32 @@ | ||
module ClientOrders | ||
class RegisterProduct | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)) | ||
module ProductHandlers | ||
class RegisterProduct | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)) | ||
end | ||
end | ||
end | ||
|
||
class ChangeProductName | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update( | ||
name: event.data.fetch(:name) | ||
) | ||
class ChangeProductName | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update( | ||
name: event.data.fetch(:name) | ||
) | ||
end | ||
end | ||
end | ||
|
||
class ChangeProductPrice | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(price: event.data.fetch(:price)) | ||
class ChangeProductPrice | ||
def call(event) | ||
Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(price: event.data.fetch(:price)) | ||
end | ||
end | ||
end | ||
|
||
class UpdateProductAvailability | ||
def call(event) | ||
product = Product.find_by(uid: event.data.fetch(:product_id)) | ||
available = event.data.fetch(:available) | ||
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?) | ||
product.update(available: available.positive?) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.