Class: AuctionFunCore::Repos::UserContext::UserRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/auction_fun_core/repos/user_context/user_repository.rb

Overview

Repository for handling repository operations related to users.

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

Examples:

user_repo = AuctionFunCore::Repos::UserContext::UserRepository.new

# Retrieve all users
all_users = user_repo.all

# Get the total number of users
total_users = user_repo.count

# Find a user by its ID
user = user_repo.by_id(123)

# Find a user by its ID and raise an error if not found
user = user_repo.by_id!(123)

# Search for a user by email or phone
user = user_repo.('[email protected]')
user = user_repo.('1234567890')

# Search for a user by email confirmation token
user = user_repo.by_email_confirmation_token('email_confirmation_token')

# Search for a user by phone confirmation token
user = user_repo.by_phone_confirmation_token('phone_confirmation_token')

See Also:

Instance Method Summary collapse

Instance Method Details

#allArray<ROM::Struct::User>

Returns all users in database.

Returns:

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


48
49
50
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 48

def all
  users.to_a
end

#by_email_confirmation_token(email_confirmation_token) ⇒ ROM::Struct::User?

Searches for a user in the database by email confirmation token.

Parameters:

  • email_confirmation_token (String)

    The email confirmation token of the user.

Returns:

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

    The user found with the provided email confirmation token, or nil if not found.



99
100
101
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 99

def by_email_confirmation_token(email_confirmation_token)
  users.where(Sequel[email_confirmation_token: email_confirmation_token]).one
end

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

Retrieves a user from the database by its primary key.

Parameters:

  • id (Integer)

    The ID of the user to retrieve.

Returns:

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

    The retrieved user, or nil if not found.



71
72
73
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 71

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

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

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

Parameters:

  • id (Integer)

    The ID of the user to retrieve.

Returns:

  • (ROM::Struct::User)

    The retrieved user.

Raises:

  • (ROM::TupleCountMismatchError)

    if the user is not found.



81
82
83
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 81

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

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

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

Parameters:

  • login (String)

    The email or phone of the user.

Returns:

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

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



90
91
92
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 90

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

#by_phone_confirmation_token(phone_confirmation_token) ⇒ ROM::Struct::User?

Searches for a user in the database by phone confirmation token.

Parameters:

  • phone_confirmation_token (String)

    The phone confirmation token of the user.

Returns:

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

    The user found with the provided phone confirmation token, or nil if not found.



108
109
110
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 108

def by_phone_confirmation_token(phone_confirmation_token)
  users.where(Sequel[phone_confirmation_token: phone_confirmation_token]).one
end

#countInteger

Returns the total number of users in database.

Returns:

  • (Integer)


54
55
56
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 54

def count
  users.count
end

#exists?(conditions) ⇒ Boolean

Checks if a user exists based on the provided conditions.

Parameters:

  • conditions (Hash)

    The conditions to check (DSL Dataset).

Returns:

  • (Boolean)

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



116
117
118
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 116

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

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

Constructs SQL conditions for querying users in the database.

Parameters:

  • conditions (Hash)

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

Returns:



62
63
64
# File 'lib/auction_fun_core/repos/user_context/user_repository.rb', line 62

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