RailsEventStore/cqrs-es-sample-with-res

View on GitHub
ecommerce/crm/lib/crm/customer_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
module Crm

  class OnRegistration
    def initialize(event_store)
      @repository = Infra::AggregateRootRepository.new(event_store)
    end

    def call(command)
      @repository.with_aggregate(Customer, command.aggregate_id) do |customer|
        customer.register(command.name)
      end
    end
  end

  class OnPromoteCustomerToVip
    def initialize(event_store)
      @repository = Infra::AggregateRootRepository.new(event_store)
    end

    def call(command)
      @repository.with_aggregate(Customer, command.aggregate_id) do |customer|
        customer.promote_to_vip
      end
    end
  end

end