Class: AuctionFunCore::Repos::AuctionContext::AuctionRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/auction_fun_core/repos/auction_context/auction_repository.rb

Overview

Repository for handling repository operations related to auctions.

This repository provides methods to interact with auction data in the database, including creating, updating, deleting, and retrieving auctions.

Examples:

auction_repo = AuctionFunCore::Repos::AuctionContext::AuctionRepository.new

# Retrieve all auctions
all_auctions = auction_repo.all

# Get the total number of auctions
total_auctions = auction_repo.count

# Find an auction by its ID
auction = auction_repo.by_id(123)

# Find an auction by its ID and raise an error if not found
auction = auction_repo.by_id!(123)

See Also:

Instance Method Summary collapse

Instance Method Details

#allArray<ROM::Struct::Auction>

Returns all auctions in the database.

Returns:

  • (Array<ROM::Struct::Auction>)


38
39
40
# File 'lib/auction_fun_core/repos/auction_context/auction_repository.rb', line 38

def all
  auctions.to_a
end

#by_id(id) ⇒ ROM::Struct::Auction?

Retrieves an auction from the database by its primary key.

Parameters:

  • id (Integer)

    The ID of the auction to retrieve.

Returns:

  • (ROM::Struct::Auction, nil)

    The retrieved auction, or nil if not found.



55
56
57
# File 'lib/auction_fun_core/repos/auction_context/auction_repository.rb', line 55

def by_id(id)
  auctions.by_pk(id).one
end

#by_id!(id) ⇒ ROM::Struct::Auction

Retrieves an auction from the database by its primary key, raising an error if not found.

Parameters:

  • id (Integer)

    The ID of the auction to retrieve.

Returns:

  • (ROM::Struct::Auction)

    The retrieved auction.

Raises:

  • (ROM::TupleCountMismatchError)

    if the auction is not found.



65
66
67
# File 'lib/auction_fun_core/repos/auction_context/auction_repository.rb', line 65

def by_id!(id)
  auctions.by_pk(id).one!
end

#countInteger

Returns the total number of auctions in the database.

Returns:

  • (Integer)

    Total number of auctions.



46
47
48
# File 'lib/auction_fun_core/repos/auction_context/auction_repository.rb', line 46

def count
  auctions.count
end