Routes
Module contents
This package contains all route definitions (endpoints) for the application, typically grouped by functionality or resource.
Submodules
Api_routes module
Streaming_routes module
WebSocket endpoints for real-time messaging and notifications.
This module provides WebSocket routes for chat message exchange and user connection tracking. Authentication is required for both endpoints via a query parameter token.
Routes: - /messages: WebSocket for real-time chat messaging. - /notifications: WebSocket for real-time notifications. - /connected_users: HTTP endpoint to retrieve the list of connected clients.
- async back_chat.routes.streaming_routes.get_connected_users()[source]
Retrieve the list of currently connected WebSocket client IDs.
- Returns:
Dictionary containing a list of connected user IDs.
- async back_chat.routes.streaming_routes.websocket_endpoint(websocket: WebSocket, token: str = Query(PydanticUndefined))[source]
WebSocket endpoint for receiving real-time notifications.
Clients must authenticate using a token passed as a query parameter. The connection is registered with a combination of client ID and IP:port. Incoming messages are parsed as notifications.
- Parameters:
websocket – WebSocket connection instance.
token – Authentication token passed as a query parameter.
V1_routes module
REST API endpoints for user management, message handling, and file uploads.
Includes:
Add, update, list and delete users.
Upload files.
Get recent messages and delete them.
Retrieve user configuration from request token.
Track connected users via WebSocket manager.
- back_chat.routes.v1_routes.adding_user(user_parameter: UserSchema) JSONResponse [source]
Add a new user to the database.
Handles exceptions and logs any errors that may occur during creation.
- Parameters:
user_parameter – User data to be added.
- Returns:
JSON response indicating success or failure.
- back_chat.routes.v1_routes.delete_messages()[source]
Delete all chat messages from the database.
- Returns:
Confirmation message.
- back_chat.routes.v1_routes.delete_user(user_id: int)[source]
Delete a user by ID.
- Parameters:
user_id – ID of the user to delete.
- Returns:
Success message or 404 if user not found.
- async back_chat.routes.v1_routes.get_connected_users() List[UserConnection] [source]
Get the list of currently connected WebSocket users.
- Returns:
List of user names wrapped in UserConnection schema.
- back_chat.routes.v1_routes.get_messages(request: Request) List[MessageSchema] [source]
Retrieve the 10 most recent messages.
Marks messages as “isMine=True” if sent by the requesting user.
- Parameters:
request – HTTP request used to determine current user.
- Returns:
List of MessageSchema objects sorted oldest to newest.
- back_chat.routes.v1_routes.get_user_conf(request: Request) JSONResponse [source]
Retrieve user configuration from the request’s authentication token.
- Parameters:
request – HTTP request object containing headers and cookies.
- Returns:
JSON response with user configuration or 400 if not found.
- back_chat.routes.v1_routes.updating_user(user_id: str, user_update: UserSchema)[source]
Update an existing user.
- Parameters:
user_id – ID of the user to update.
user_update – Updated user data.
- Returns:
Updated user object or 404 if not found.