Class: AuctionFunCore::Operations::AuctionContext::PostAuction::WinnerOperation

Inherits:
Base
  • Object
show all
Defined in:
lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb

Overview

Operation class for managing winners in auctions.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(attributes) {|Dry::Matcher::Evaluator| ... } ⇒ Dry::Matcher::Evaluator

Executes the winner operation with the provided attributes.

Examples:

attributes = { auction_id: 123, winner_id: 123 }

AuctionFunCore::Operations::AuctionContext::PostAuction::WinnerOperation.call(attributes) do |result|
  result.success { |auction| puts "Winner operation completed successfully! #{auction.to_h}" }
  result.failure { |failure| puts "Failed auction winner operation: #{failure.errors.to_h}"}
end

Parameters:

  • attributes (Hash)

    The attributes for the winner operation.

Options Hash (attributes):

  • auction_id (Integer)

    The ID of the auction.

  • winner_id (Integer)

    The winning user ID

Yields:

  • (Dry::Matcher::Evaluator)

    The block to handle the result of the operation.

Returns:

  • (Dry::Matcher::Evaluator)

    The result of the operation.



31
32
33
34
35
36
37
# File 'lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb', line 31

def self.call(attributes, &block)
  operation = new.call(attributes)

  return operation unless block

  Dry::Matcher::ResultMatcher.call(operation, &block)
end

Instance Method Details

#call(attributes) ⇒ Dry::Monads::Result

Executes the winner operation.

Parameters:

  • attributes (Hash)

    The attributes for the winner operation.

Returns:

  • (Dry::Monads::Result)

    The result of the operation.



45
46
47
48
49
50
51
52
53
# File 'lib/auction_fun_core/operations/auction_context/post_auction/winner_operation.rb', line 45

def call(attributes)
  auction, winner = yield validate_contract(attributes)

  user_repository.transaction do |_t|
    send_winner_email_with_statistics_and_payment_instructions(auction.id, winner.id)
  end

  Success([auction, winner])
end