routes.users#

Module Contents#

Functions#

get_user_avatar

Endpoint to upload and update the user’s avatar.

get_current_user

Endpoint to retrieve the information of the currently authenticated user.

get_user_profile

Endpoint to retrieve the profile information of a specific user by username.

update_own_profile

Endpoint to update the profile of the currently authenticated user.

ban_user

Endpoint to ban a user by the admin.

Data#

API#

routes.users.router = 'APIRouter(...)'#
async routes.users.get_user_avatar(file: fastapi.UploadFile = File(), user: src.entity.models.User = Depends(auth_service.get_current_user), db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Endpoint to upload and update the user’s avatar.

Parameters:
  • file (UploadFile) – The avatar image file to be uploaded.

  • user (User) – Current authenticated user (dependency injection).

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

Returns:

The updated user information.

Return type:

UserResponse

async routes.users.get_current_user(user: src.entity.models.User = Depends(auth_service.get_current_user), db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Endpoint to retrieve the information of the currently authenticated user.

Parameters:
  • user (User) – Current authenticated user (dependency injection).

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

Returns:

The information of the currently authenticated user.

Return type:

UserResponse

async routes.users.get_user_profile(username: str, db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Endpoint to retrieve the profile information of a specific user by username.

Parameters:
  • username (str) – Username of the user to be retrieved.

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

Returns:

The profile information of the specified user.

Return type:

AnotherUsers

Raises:

HTTPException – If the user is not found.

async routes.users.update_own_profile(user_update: src.schemas.users.UserUpdate, user: src.entity.models.User = Depends(auth_service.get_current_user), db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Endpoint to update the profile of the currently authenticated user.

Parameters:
  • user_update (UserUpdate) – UserUpdate instance containing the updated user information.

  • user (User) – Current authenticated user (dependency injection).

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

Returns:

The updated user information.

Return type:

UserResponse

async routes.users.ban_user(username: str, current_user: src.entity.models.User = Depends(auth_service.get_current_user), db: sqlalchemy.ext.asyncio.AsyncSession = Depends(get_db))#

Endpoint to ban a user by the admin.

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

  • current_user (User) – Current authenticated user (dependency injection).

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

Raises:

HTTPException – If the current user is not an admin or if the user to be banned is not found.

Returns:

A message indicating the success of the operation.

Return type:

dict