Class: AuctionFunCore::Relations::Bids

Inherits:
Object
  • Object
show all
Defined in:
lib/auction_fun_core/relations/bids.rb

Overview

SQL relation for bids

Instance Method Summary collapse

Instance Method Details

#participants(auction_id) ⇒ Array<Integer>

Retrieves a list of unique user IDs who have placed bids in a specified auction. A participant in an auction is defined as a user who has placed one or more bids.

Parameters:

  • auction_id (Integer)

    the ID of the auction.

Returns:

  • (Array<Integer>)

    Returns an array of unique user IDs who have participated in the auction.

Raises:

  • (RuntimeError)

    Raises an error if the auction_id is not an integer.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/auction_fun_core/relations/bids.rb', line 33

def participants(auction_id)
  raise "Invalid argument" unless auction_id.is_a?(Integer)

  sql = <<-SQL
    SELECT COALESCE(ARRAY_AGG(DISTINCT user_id), ARRAY[]::INT[]) AS participant_ids
    FROM bids
    WHERE auction_id = #{auction_id}
  SQL

  read(sql)
end