Class: AuctionFunCore::Repos::StaffContext::StaffRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/auction_fun_core/repos/staff_context/staff_repository.rb

Overview

Repository for handling repository operations related to staffs.

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

Examples:

staff_repo = AuctionFunCore::Repos::StaffContext::StaffRepository.new

# Retrieve all staffs
all_staffs = staff_repo.all

# Get the total number of staffs
total_staffs = staff_repo.count

# Search staffs based on certain conditions
conditions = {name: 'Staff'}
search = staff_repo.query(conditions)

# Find an staff by its ID
staff = staff_repo.by_id(123)

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

# Search for a staff by email or phone
 = staff_repo.('[email protected]')

# Check if a staff exists based on certain conditions
conditions = { name: 'John Doe' }
staff_exists = staff_repo.exists?(conditions)

See Also:

Instance Method Summary collapse

Instance Method Details

#allArray<ROM::Struct::Staff>

Returns all staffs in database.

Returns:

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


49
50
51
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 49

def all
  staffs.to_a
end

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

Retrieves an staff from the database by its primary key.

Parameters:

  • id (Integer)

    The ID of the staff to retrieve.

Returns:

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

    The retrieved staff, or nil if not found.



73
74
75
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 73

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

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

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

Parameters:

  • id (Integer)

    The ID of the staff to retrieve.

Returns:

  • (ROM::Struct::Staff)

    The retrieved staff.

Raises:

  • (ROM::TupleCountMismatchError)

    if the staff is not found.



83
84
85
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 83

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

#by_login(login) ⇒ ROM::Struct::Staff?

Searches for a staff in the database by email or phone keys.

Parameters:

  • login (String)

    The email or phone of the staff.

Returns:

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

    The staff found with the provided email or phone, or nil if not found.



92
93
94
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 92

def ()
  staffs.where(Sequel[email: ] | Sequel[phone: ]).one
end

#countInteger

Returns the total number of staffs in the database.

Returns:

  • (Integer)

    Total number of staffs.



56
57
58
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 56

def count
  staffs.count
end

#exists?(conditions) ⇒ Boolean

Checks if a bid exists based on the provided conditions.

Parameters:

  • conditions (Hash)

    The conditions to check (DSL Dataset).

Returns:

  • (Boolean)

    true if a staff exists that matches the conditions, otherwise false.



100
101
102
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 100

def exists?(conditions)
  staffs.exist?(conditions)
end

#query(conditions) ⇒ AuctionFunCore::Relations::Staff

Constructs SQL conditions for querying staffs in the database.

Parameters:

  • conditions (Hash)

    The conditions to be used in the query (DSL Dataset).

Returns:

  • (AuctionFunCore::Relations::Staff)

    The relation containing the staffs that match the given conditions.



64
65
66
# File 'lib/auction_fun_core/repos/staff_context/staff_repository.rb', line 64

def query(conditions)
  staffs.where(conditions)
end