add basic usecase layer
parent
b453880cf4
commit
6b2ab75561
|
|
@ -0,0 +1,8 @@
|
|||
from typing import Optional, List
|
||||
|
||||
class CartRepositoryInterface:
|
||||
def fetch_cart_by_user_id(self, user_id: int) -> Optional[List[dict]]:
|
||||
"""
|
||||
Abstract method to fetch cart data by user ID.
|
||||
"""
|
||||
raise NotImplementedError("fetch_cart_by_user_id must be implemented by a subclass")
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#python imports
|
||||
from typing import Optional
|
||||
|
||||
#dependency imports
|
||||
from entities.cart import Cart, CartItem
|
||||
from interface_adapters.cart_repository import CartRepository
|
||||
|
||||
class ViewCart:
|
||||
def __init__(self, cart_repository: CartRepository):
|
||||
self.cart_repository = cart_repository
|
||||
|
||||
def execute(self, user_id: int) -> Optional[Cart]:
|
||||
"""
|
||||
Fetches the cart data from the repository, converts it to Cart entity.
|
||||
"""
|
||||
cart_data = self.cart_repository.fetch_cart_by_user_id(user_id)
|
||||
if not cart_data:
|
||||
return None
|
||||
|
||||
# Convert raw data to domain entities
|
||||
items = [CartItem(**item) for item in cart_data]
|
||||
return Cart(items)
|
||||
Loading…
Reference in New Issue