Move from a direct access to DB by the parsers/categorizers to a middle layer, which will bring an easier way to have two input alternatives. This patch starts by instantiating the manager on the cli runnable and using it for the parser function. This patch also moves the queries to a different file, so that introducing new functions on the DB client becomes more manageable and clearer. Finally, the new manager will need converters to move from the code type Transaction to the DB types. This will eventually simplify the code data model by removing more of its method and leaving it a simple dataclass. Issue #14
21 lines
642 B
Python
21 lines
642 B
Python
from pfbudget.core.input.parsers import parse_data
|
|
from pfbudget.core.transactions import Transaction
|
|
from pfbudget.db.client import DatabaseClient
|
|
from pfbudget.utils.converters import convert
|
|
|
|
|
|
class Manager:
|
|
def __init__(self, db: str):
|
|
self.__db = DatabaseClient(db)
|
|
|
|
def transactions() -> list[Transaction]:
|
|
pass
|
|
|
|
def add_transactions(self, transactions: list[Transaction]):
|
|
converted = convert(transactions)
|
|
self.__db.insert_transactions(converted)
|
|
|
|
def parse(self, filename: str, args: dict):
|
|
transactions = parse_data(filename, args)
|
|
self.add_transactions(transactions)
|