Source code for eclypse.builders.application.sock_shop.mpi_services.user

"""The `UserService` class.

It manages all user-related functionality, including registration,\
    authentication, and profile management.

- Key Responsibilities:
    - Handles user sign-up, login, and logout processes.
    - Manages user data, including credentials, personal information, and addresses.
"""

from eclypse.remote.communication import mpi
from eclypse.remote.service import Service
from eclypse.utils import format_log_kv


[docs] class UserService(Service): """MPI workflow of the User service."""
[docs] async def step(self): """Example workflow of the `UserService` class. It starts with fetching the user's profile information. """ await self.frontend_request() # pylint: disable=no-value-for-parameter
@mpi.exchange(receive=True, send=True) def frontend_request(self, sender_id, body): """Process the frontend request and send the response to the `FrontendService`. Args: sender_id (str): The ID of the sender. body (dict): The request body. Returns: str: The ID of the recipient. dict: The response body. """ self.logger.info("Received request | " + format_log_kv(request=body)) # Send response to FrontendService if body.get("request_type") == "user_data": frontend_response = { "response_type": "user_response", "name": "John Doe", "email": "john@example.com", "address": "123 Main St", "phone": "555-1234", } else: frontend_response = { "response_type": "user_response", "status": "Invalid request", } return sender_id, frontend_response