get balance
parent
f100f00c0d
commit
0de79b165f
|
@ -1,14 +1,18 @@
|
|||
# from clifinance.application.dto.balance import Balance
|
||||
# from clifinance.domain.expense.gateway import ExpenseGateway
|
||||
#
|
||||
#
|
||||
# class GetBalance:
|
||||
# def __init__(
|
||||
# self,
|
||||
# gateway: ExpenseGateway,
|
||||
# ) -> None:
|
||||
# self.__gateway = gateway
|
||||
#
|
||||
# def __call__(self) -> Balance:
|
||||
#
|
||||
# return self.__gateway.get_balance()
|
||||
from clifinance.application.dto.balance import Balance
|
||||
from clifinance.domain.expense.gateway import ExpenseGateway
|
||||
from clifinance.domain.expense.model import ExpenseType
|
||||
|
||||
|
||||
class GetBalance:
|
||||
def __init__(
|
||||
self,
|
||||
gateway: ExpenseGateway,
|
||||
) -> None:
|
||||
self.__gateway = gateway
|
||||
|
||||
def __call__(self) -> Balance:
|
||||
return Balance(
|
||||
balance=sum(e.amount.value for e in self.__gateway.get_all_expenses()),
|
||||
imcome_balance=sum(e.amount.value for e in self.__gateway.get_all_expenses_by_type(ExpenseType.INCOME)),
|
||||
expense_balance=sum(e.amount.value for e in self.__gateway.get_all_expenses_by_type(ExpenseType.EXPENSE)),
|
||||
)
|
||||
|
|
|
@ -7,8 +7,7 @@ from typing import ParamSpec, TypeVar
|
|||
from clifinance.application.abstractions.protocols.driver import FileDriver
|
||||
from clifinance.application.abstractions.protocols.session import Session
|
||||
from clifinance.application.usecases.add_expense import AddExpense
|
||||
|
||||
# from clifinance.application.usecases.get_balance import GetBalance
|
||||
from clifinance.application.usecases.get_balance import GetBalance
|
||||
from clifinance.domain.expense.gateway import ExpenseGateway
|
||||
from clifinance.infrastructure.persistence.json_driver import JsonFileDriver
|
||||
from clifinance.infrastructure.persistence.json_gateway import JsonExpenseGateway
|
||||
|
@ -17,9 +16,9 @@ from clifinance.infrastructure.session import JsonFileSession
|
|||
|
||||
class Container:
|
||||
|
||||
# @contextmanager
|
||||
# def provide_get_balance(self) -> Generator[GetBalance, None, None]:
|
||||
# yield GetBalance(gateway=self.json_gateway())
|
||||
@contextmanager
|
||||
def provide_get_balance(self) -> Generator[GetBalance, None, None]:
|
||||
yield GetBalance(gateway=self.json_gateway())
|
||||
|
||||
@contextmanager
|
||||
def provide_add_expense(self) -> Generator[AddExpense, None, None]:
|
||||
|
|
|
@ -5,8 +5,8 @@ from clifinance.main.container import Container
|
|||
|
||||
|
||||
def get_balance(args: argparse.Namespace, ioc: Container) -> None:
|
||||
# with ioc.provide_get_balance() as usecase:
|
||||
# print(usecase())
|
||||
with ioc.provide_get_balance() as usecase:
|
||||
print(usecase())
|
||||
print()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue