fix: address account valuation review findings
This commit is contained in:
@@ -5,6 +5,7 @@ import sqlite3 as sqlite3
|
||||
import hashlib
|
||||
import json
|
||||
import re
|
||||
from functools import wraps
|
||||
from datetime import date, datetime, timedelta
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
@@ -23,6 +24,8 @@ from ..infrastructure.parsers import (
|
||||
)
|
||||
from ..infrastructure.sqlite import db as db
|
||||
from ..infrastructure.sqlite import init_db as init_db
|
||||
from ..infrastructure.sqlite import read_db as read_db
|
||||
from ..infrastructure.sqlite import DatabaseNotInitializedError
|
||||
from ..infrastructure.sqlite import resolve_db_path as resolve_db_path
|
||||
|
||||
VALID_TRANSACTION_TYPES = {"income", "expense", "transfer", "refund", "adjustment"}
|
||||
@@ -121,6 +124,19 @@ def ok(**data: Any) -> dict[str, Any]:
|
||||
def fail(error_code: str, message: str, **data: Any) -> dict[str, Any]:
|
||||
return {"success": False, "error_code": error_code, "error": message, **data}
|
||||
|
||||
|
||||
def read_operation(function):
|
||||
"""Translate missing/read-only SQLite failures to the public envelope."""
|
||||
@wraps(function)
|
||||
def wrapped(*args, **kwargs):
|
||||
try:
|
||||
return function(*args, **kwargs)
|
||||
except DatabaseNotInitializedError:
|
||||
return fail("db_not_initialized", "ledger database is not initialized")
|
||||
except sqlite3.Error:
|
||||
return fail("db_error", "ledger database read failed")
|
||||
return wrapped
|
||||
|
||||
def row_to_dict(row: Any) -> dict[str, Any]:
|
||||
d = dict(row)
|
||||
if "tags" in d:
|
||||
|
||||
Reference in New Issue
Block a user