simpler folder structure. remove __init__.py since it might be confusing
parent
531db9fd02
commit
be29f9b878
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
#python imports
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
|
||||
class ProductDTO(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
description: str
|
||||
price: float
|
||||
|
|
@ -8,11 +8,15 @@ from pydantic import BaseModel
|
|||
|
||||
#dependency imports
|
||||
from entities.product import Product
|
||||
from use_cases.interactors import ViewProduct, ViewAllProducts
|
||||
from use_cases.interfaces.ports import IViewProductInputPort, IViewAllProductsInputPort, IViewProductOutputPort, IViewAllProductsOutputPort
|
||||
from interface_adapters.dtos import ProductDTO
|
||||
from interface_adapters.repositories import SQLProductRepository
|
||||
from use_cases.view_all_products import ViewAllProducts, IViewAllProductsInputPort, IViewAllProductsOutputPort
|
||||
from use_cases.view_product import ViewProduct, IViewProductInputPort, IViewProductOutputPort
|
||||
from interface_adapters.sql_product_repository import SQLProductRepository
|
||||
|
||||
class ProductDTO(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
description: str
|
||||
price: float
|
||||
|
||||
class ViewProductRequest(BaseModel):
|
||||
product_id: int
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -3,8 +3,8 @@ from typing import Optional, List
|
|||
import sqlite3
|
||||
|
||||
#dependency imports
|
||||
from use_cases.interfaces.repositories import IProductRepository
|
||||
from entities import Product
|
||||
from use_cases.product_repository import IProductRepository
|
||||
from entities.product import Product
|
||||
|
||||
class SQLProductRepository(IProductRepository):
|
||||
def __init__(self, db_file="framework_driver/db/shop.db"):
|
||||
|
|
@ -3,8 +3,8 @@ from typing import Optional, List
|
|||
import sqlite3
|
||||
|
||||
#dependency imports
|
||||
from use_cases.interfaces.repositories import IUserRepository
|
||||
from entities import User
|
||||
from use_cases.user_repository import IUserRepository
|
||||
from entities.user import User
|
||||
|
||||
class SQLUserRepository(IUserRepository):
|
||||
def __init__(self, db_file="framework_driver/db/shop.db"):
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
from interface_adapters.controllers.product_controller import router as product_router
|
||||
from interface_adapters.controllers.user_controller import router as user_router
|
||||
from interface_adapters.product_controller import router as product_router
|
||||
from interface_adapters.user_controller import router as user_router
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import RedirectResponse
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from framework_driver.db import db_setup
|
||||
from interface_adapters.repositories import sql_product_repository
|
||||
from interface_adapters.repositories import sql_user_repository
|
||||
from interface_adapters import sql_product_repository
|
||||
from interface_adapters import sql_user_repository
|
||||
db_setup.main()
|
||||
sql_product_repository.main()
|
||||
sql_user_repository.main()
|
||||
|
|
@ -4,6 +4,10 @@ from typing import Optional
|
|||
#dependency imports
|
||||
#TODO: use correct dependencies
|
||||
|
||||
#TODO: Create InputPort
|
||||
|
||||
#TODO: Create OutputPort
|
||||
|
||||
class CreateUser:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#python imports
|
||||
from typing import Optional, List
|
||||
|
||||
#dependency imports
|
||||
from entities import Product
|
||||
from use_cases.interfaces.repositories import IProductRepository
|
||||
from use_cases.interfaces.ports import IViewAllProductsInputPort, IViewAllProductsOutputPort
|
||||
|
||||
class ViewAllProducts(IViewAllProductsInputPort):
|
||||
def __init__(self, product_repository: IProductRepository, output_port: IViewAllProductsOutputPort):
|
||||
self.product_repository = product_repository
|
||||
self.output_port = output_port
|
||||
|
||||
def execute(self) -> Optional[List[Product]]:
|
||||
"""
|
||||
Fetches the product data from the repository.
|
||||
"""
|
||||
product_data = self.product_repository.get_all_products()
|
||||
if not product_data:
|
||||
return None
|
||||
return self.output_port.present(product_data)
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#python imports
|
||||
from typing import Optional
|
||||
|
||||
#dependency imports
|
||||
from entities import Product
|
||||
from use_cases.interfaces.repositories import IProductRepository
|
||||
from use_cases.interfaces.ports import IViewProductInputPort, IViewProductOutputPort
|
||||
|
||||
class ViewProduct(IViewProductInputPort):
|
||||
def __init__(self, product_repository: IProductRepository, output_port: IViewProductOutputPort):
|
||||
self.product_repository = product_repository
|
||||
self.output_port = output_port
|
||||
|
||||
def execute(self, product_id: int) -> Optional[Product]:
|
||||
"""
|
||||
Fetches the product data from the repository.
|
||||
"""
|
||||
product_data = self.product_repository.get_product_by_id(product_id)
|
||||
if not product_data:
|
||||
return None
|
||||
|
||||
return self.output_port.present(product_data)
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
class IViewAllProductsInputPort:
|
||||
def execute(self):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
from entities import Product
|
||||
from typing import List
|
||||
class IViewAllProductsOutputPort:
|
||||
def present(self, product_list:List[Product]):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
class IViewProductInputPort:
|
||||
def execute(self, product_id:int):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
from entities import Product
|
||||
class IViewProductOutputPort:
|
||||
def present(self, product:Product):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
import importlib
|
||||
import pkgutil
|
||||
import inspect
|
||||
|
||||
__all__ = []
|
||||
for loader, module_name, is_pkg in pkgutil.walk_packages(__path__):
|
||||
module = importlib.import_module(f".{module_name}", __name__)
|
||||
for name, obj in inspect.getmembers(module, inspect.isclass):
|
||||
if obj.__module__ == module.__name__:
|
||||
globals()[name] = obj
|
||||
__all__.append(name)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Optional, List
|
||||
|
||||
#dependency imports
|
||||
from entities import Product
|
||||
from entities.product import Product
|
||||
|
||||
class IProductRepository:
|
||||
def get_product_by_id(self, product_id: int) -> Optional[Product]:
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#python imports
|
||||
from typing import Optional, List
|
||||
|
||||
#dependency imports
|
||||
from entities.product import Product
|
||||
from use_cases.product_repository import IProductRepository
|
||||
|
||||
class IViewAllProductsInputPort:
|
||||
def execute(self):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
||||
class IViewAllProductsOutputPort:
|
||||
def present(self, product_list:List[Product]):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
||||
class ViewAllProducts(IViewAllProductsInputPort):
|
||||
def __init__(self, product_repository: IProductRepository, output_port: IViewAllProductsOutputPort):
|
||||
self.product_repository = product_repository
|
||||
self.output_port = output_port
|
||||
|
||||
def execute(self) -> Optional[List[Product]]:
|
||||
"""
|
||||
Fetches the product data from the repository.
|
||||
"""
|
||||
product_data = self.product_repository.get_all_products()
|
||||
if not product_data:
|
||||
return None
|
||||
return self.output_port.present(product_data)
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
#python imports
|
||||
from typing import Optional
|
||||
|
||||
#dependency imports
|
||||
from entities.product import Product
|
||||
from use_cases.product_repository import IProductRepository
|
||||
|
||||
class IViewProductInputPort:
|
||||
def execute(self, product_id:int):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
||||
class IViewProductOutputPort:
|
||||
def present(self, product:Product):
|
||||
"""
|
||||
Abstract method to execute use case.
|
||||
"""
|
||||
raise NotImplementedError("execute must be implemented by a subclass")
|
||||
|
||||
class ViewProduct(IViewProductInputPort):
|
||||
def __init__(self, product_repository: IProductRepository, output_port: IViewProductOutputPort):
|
||||
self.product_repository = product_repository
|
||||
self.output_port = output_port
|
||||
|
||||
def execute(self, product_id: int):
|
||||
"""
|
||||
Fetches the product data from the repository.
|
||||
"""
|
||||
product_data = self.product_repository.get_product_by_id(product_id)
|
||||
if not product_data:
|
||||
return None
|
||||
|
||||
return self.output_port.present(product_data)
|
||||
Loading…
Reference in New Issue