Source code for eclypse.builders.application.sock_shop.rest_services.cart
"""The `CartService` handles the shopping cart functionality.
- Key Responsibilities:
- Manages the user's shopping cart by adding, removing, or updating items.
- Stores cart data temporarily for guest users or long-term for registered users.
"""
from eclypse.remote.communication import rest
from eclypse.remote.service import RESTService
from eclypse.utils import format_log_kv
[docs]
class CartService(RESTService):
"""REST endpoints for the Cart service."""
[docs]
@rest.endpoint("/cart", "GET")
def get_cart(self, **_):
"""Get the user's shopping cart.
Returns:
int: The HTTP status code.
dict: The response body.
Example:
.. code-block:: python
(
200,
{
"items": [
{"id": "1", "quantity": 2},
{"id": "2", "quantity": 1},
],
},
)
"""
self.logger.info("Received request | " + format_log_kv())
return 200, {
"items": [
{"id": "1", "quantity": 2},
{"id": "2", "quantity": 1},
],
}