RailsEventStore/cqrs-es-sample-with-res

View on GitHub
rails_application/app/read_models/client_orders/change_product_name.rb

Summary

Maintainability
A
20 mins
Test Coverage
module ClientOrders
  class ChangeProductName < Infra::EventHandler
    def call(event)
      ApplicationRecord.with_advisory_lock(event.data.fetch(:product_id)) do
        Product.find_or_create_by(uid: event.data.fetch(:product_id)).update(
          name: event.data.fetch(:name)
        )
      end
    end
  end
end