repository.users#

Module Contents#

Functions#

get_user_by_email

Retrieve a user from the database based on the email.

create_user

Create a new user in the database.

check_is_first_user

Check if the database has any users.

update_token

Update the refresh token for a user in the database.

update_avatar

Update the avatar for a user and add a new picture entry to the database.

get_user_by_username

Retrieve a user from the database based on the full name.

update_user

Update user information in the database.

get_picture_count

Get the count of pictures associated with a user and update the user instance.

ban_user

Ban a user by updating the ‘ban’ attribute in the database.

API#

async repository.users.get_user_by_email(email: str, db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Retrieve a user from the database based on the email.

Parameters:
  • email (str) – Email of the user to be retrieved.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

The retrieved user or None if not found.

Return type:

User or None

async repository.users.create_user(body: src.schemas.users.UserSchema, db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Create a new user in the database.

Parameters:
  • body (UserSchema) – UserSchema instance containing user data.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

The created user.

Return type:

User

async repository.users.check_is_first_user(db: sqlalchemy.ext.asyncio.AsyncSession)#

Check if the database has any users.

Parameters:

db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

True if the database has no users, False otherwise.

Return type:

bool

async repository.users.update_token(user: src.entity.models.User, token: str | None, db: sqlalchemy.ext.asyncio.AsyncSession)#

Update the refresh token for a user in the database.

Parameters:
  • user (User) – User instance to update.

  • token (str or None) – New refresh token or None to clear the token.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

async repository.users.update_avatar(full_name, url: str, db: sqlalchemy.ext.asyncio.AsyncSession, public_id) src.entity.models.User#

Update the avatar for a user and add a new picture entry to the database.

Parameters:
  • full_name (str) – Full name of the user.

  • url (str) – URL of the new avatar.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

  • public_id (str) – Public ID associated with the avatar in Cloudinary.

Returns:

The updated user instance.

Return type:

User

async repository.users.get_user_by_username(full_name: str, db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Retrieve a user from the database based on the full name.

Parameters:
  • full_name (str) – Full name of the user to be retrieved.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

The retrieved user or None if not found.

Return type:

User or None

async repository.users.update_user(email: str, user_update: src.schemas.users.UserUpdate, db: sqlalchemy.ext.asyncio.AsyncSession)#

Update user information in the database.

Parameters:
  • email (str) – Email of the user to be updated.

  • user_update (UserUpdate) – UserUpdate instance containing updated user data.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

The updated user instance or None if the user does not exist.

Return type:

User or None

async repository.users.get_picture_count(db: sqlalchemy.ext.asyncio.AsyncSession, user: src.entity.models.User)#

Get the count of pictures associated with a user and update the user instance.

Parameters:
  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

  • user (User) – User instance for which the picture count is to be retrieved.

async repository.users.ban_user(username: str, db: sqlalchemy.ext.asyncio.AsyncSession)#

Ban a user by updating the ‘ban’ attribute in the database.

Parameters:
  • username (str) – Full name of the user to be banned.

  • db (AsyncSession) – Asynchronous SQLAlchemy session (dependency injection).

Returns:

True if the user is successfully banned, False otherwise.

Return type:

bool