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:

  • the ID of the auction.

Returns:

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

Raises:

  • 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 = "    SELECT COALESCE(ARRAY_AGG(DISTINCT user_id), ARRAY[]::INT[]) AS participant_ids\n    FROM bids\n    WHERE auction_id = \#{auction_id}\n  SQL\n\n  read(sql)\nend\n"