Seonghyeon Kim
Newbie developer
class FooManager:
async def get_bar(user_id: str):
stmt = f"SELECT bar, zee from foo_tbl where bar = {user_id}"
result = await MySQLSingleton.fetch(stmt)
return result
class FooRepository(ABC):
@abstracmethod
async def get_bar(user_id: str) -> Dict[str, Any]:
pass
class DynamoFooRepository:
...
async def get_bar(user_id: str) -> Dict[str, Any]:
r = await self.model.query(hash_key=user_id)
return r
class MySQLFooRepository:
...
async def get_bar(user_id: str) -> Dict[str, Any]:
stmt = "..."
r = await self.connection.fetch(stmt)
return r
class ExternServiceFooRepository:
...
async def get_bar(user_id: str) -> Dict[str, Any]:
r = await service("user").get("...")
return r
class FooManager:
repo = FooRepository(...)
async def get_bar(user_id: str) -> Dict[str, Any]:
r = self.repo(user_id)
return r
class FooManager:
def __int__(repo: FooRepositoryABC)
self.repo = repo
async def get_bar(user_id: str) -> Dict[str, Any]:
r = self.repo(user_id)
return r
class FooView(InsanicView):
manager = FooManager(DynamoFooRepository())
async def get(request: Request, user_id: str):
r = self.manger.get_bar(user_id)
return Response(json=r, status_code=200)
By Seonghyeon Kim