Files
leocrm/app/routes/bank_accounts.py
T
Agent Zero 3e7abd4518 feat: Mini-Apps registry, Stammdaten backend persistence, bank accounts
- Register 6 mini-apps in kommunikation plugin (contact_picker, file_share,
  calendar_invite, mail_forward, ai_search, task_create)
- Connect AdressenTab to backend API (GET/POST/PATCH/DELETE /addresses)
- Create BankAccount model, schema, service, routes + migration 0033
- Connect KontenTab to backend API (GET/POST/PATCH/DELETE /bank-accounts)
- AI tools already working: 7 tools registered (hybrid_search, get_contact_mails, etc.)
2026-07-25 02:11:29 +02:00

86 lines
3.0 KiB
Python

"""Bank account routes — list, create, update, delete with tenant isolation."""
from __future__ import annotations
import uuid
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.db import get_db
from app.deps import require_permission
from app.schemas.bank_account import BankAccountCreate, BankAccountUpdate
from app.services import bank_account_service
router = APIRouter(prefix="/api/v1/bank-accounts", tags=["bank-accounts"])
@router.get("")
async def list_bank_accounts(
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(require_permission("bank-accounts:read")),
):
"""List all bank accounts for the current tenant."""
tenant_id = uuid.UUID(current_user["tenant_id"])
return await bank_account_service.list_bank_accounts(db, tenant_id)
@router.post("", status_code=status.HTTP_201_CREATED)
async def create_bank_account(
body: BankAccountCreate,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(require_permission("bank-accounts:write")),
):
"""Create a new bank account."""
tenant_id = uuid.UUID(current_user["tenant_id"])
user_id = uuid.UUID(current_user["user_id"])
data = body.model_dump()
try:
return await bank_account_service.create_bank_account(db, tenant_id, user_id, data)
except ValueError as exc:
raise HTTPException(400, detail={"detail": str(exc), "code": "invalid_value"}) from exc
@router.patch("/{account_id}")
async def update_bank_account(
account_id: str,
body: BankAccountUpdate,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(require_permission("bank-accounts:write")),
):
"""Update a bank account."""
tenant_id = uuid.UUID(current_user["tenant_id"])
user_id = uuid.UUID(current_user["user_id"])
try:
aid = uuid.UUID(account_id)
except ValueError:
raise HTTPException(400, detail={"detail": "Invalid account_id", "code": "invalid_id"}) from None
data = body.model_dump(exclude_unset=True)
result = await bank_account_service.update_bank_account(db, tenant_id, user_id, aid, data)
if result is None:
raise HTTPException(404, detail={"detail": "Bank account not found", "code": "not_found"})
return result
@router.delete("/{account_id}", status_code=status.HTTP_204_NO_CONTENT)
async def delete_bank_account(
account_id: str,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(require_permission("bank-accounts:write")),
):
"""Soft-delete a bank account."""
tenant_id = uuid.UUID(current_user["tenant_id"])
user_id = uuid.UUID(current_user["user_id"])
try:
aid = uuid.UUID(account_id)
except ValueError:
raise HTTPException(400, detail={"detail": "Invalid account_id", "code": "invalid_id"}) from None
deleted = await bank_account_service.delete_bank_account(db, tenant_id, user_id, aid)
if not deleted:
raise HTTPException(404, detail={"detail": "Bank account not found", "code": "not_found"})