0b04a05b26
- CategoryStore: 분류 항목 JSON 저장소(DATA_DIR/expense_categories.json) - 관리자 설정 페이지(/expense/settings) + 분류 CRUD API - _normalize 분류 고정목록 검증 제거 — 추가 분류 즉시 등록 폼/집계 반영 - index/reports 분류를 동적 목록으로 교체 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""개인경비(expense) 모듈.
|
|
|
|
라우터/저장소/템플릿을 한 디렉토리에서 관리한다.
|
|
- 라우터: `router.py` (FastAPI APIRouter, prefix=/expense)
|
|
- 저장소: `store.py` (DATA_DIR/expense.json, 향후 expense_db 후보)
|
|
- 템플릿: `templates/expense/index.html`
|
|
"""
|
|
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from .categories import DEFAULT_CATEGORIES, CategoryStore
|
|
from .router import router
|
|
from .store import CATEGORIES, METHODS, STATUSES, ExpenseStore
|
|
|
|
__all__ = [
|
|
"router",
|
|
"ExpenseStore",
|
|
"CategoryStore",
|
|
"DEFAULT_CATEGORIES",
|
|
"CATEGORIES",
|
|
"METHODS",
|
|
"STATUSES",
|
|
"build_expense_store",
|
|
]
|
|
|
|
|
|
def build_expense_store(*, dsn: str | None, json_path: Path) -> Any:
|
|
"""env 의 EXPENSE_DB_URL 이 있으면 DB 저장소, 없으면 JSON 저장소.
|
|
|
|
DB 저장소 실패(드라이버 미설치/접속 실패) 시 예외를 그대로 전파한다 —
|
|
의도치 않게 JSON 으로 폴백해 운영 데이터가 갈라지는 것을 막기 위함.
|
|
"""
|
|
if dsn:
|
|
from .db import ExpenseDBStore # 지연 import (개발 환경 deps 없을 수 있음)
|
|
|
|
return ExpenseDBStore(dsn)
|
|
return ExpenseStore(json_path)
|