user_service

Attributes

logger

Logger for the user service module

Classes

UserService

A service class for managing user-related operations such as creating, deleting,

Module Contents

logger

Logger for the user service module

class UserService

A service class for managing user-related operations such as creating, deleting, and retrieving user data from the database. This class interacts with the database through the DatabaseOperations module and logs operations using the setup logger.

static create_user(user_id: int, username: str) None

Create a new user in the ‘users’ table with default values.

Parameters:
  • user_id (int) – The ID of the new user.

  • username (str) – The username of the new user.

static delete_user(user_id: int) None

Delete a user from the ‘users’ table and all its relative data.

Parameters:

user_id (int) – The ID of the user to delete.

static user_exists(user_id: int) bool

Check if a user with the given ID exists in the ‘users’ table.

Parameters:

user_id (int) – The ID of the user to check.

Returns:

True if the user exists, False otherwise.

Return type:

bool

static get_username(user_id: int) str

Retrieve the username associated with a user ID.

Parameters:

user_id (int) – The ID of the user to look up.

Returns:

The username associated with the given user ID, or None if no user is found.

Return type:

str

static get_user_property(user_id: int, key: str) str | bool

Read a specific property of a user from the ‘users’ table.

Parameters:
  • user_id (int) – The ID of the user whose property is being read.

  • key (str) – The column name in the ‘users’ table to retrieve.

Returns:

The value of the specified property for the user, or None if the user is not found.

Return type:

str | bool

static update_user_property(user_id: int, key: str, value: str | bool) None

Update a specific property of a user in the ‘users’ table.

Parameters:
  • user_id (int) – The ID of the user whose property is to be updated.

  • key (str) – The column name in the ‘users’ table to update.

  • value (str | bool) – The new value for the property.

static get_user_information(user_id: int) tuple[bool, bool]

Retrieve specific information about a user.

Parameters:

user_id (int) – The ID of the user whose information is being retrieved.

Returns:

A tuple containing the response message and alert mode for the user, or (None, None) if the user is not found.

Return type:

tuple

static user_already_registered(user_id: int) bool

Check if a user is already registered in the ‘users’ table.

Parameters:

user_id (int) – The ID of the user to check.

Returns:

True if the user is registered, False otherwise.

Return type:

bool