mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 14:08:46 +02:00
All 29 call sites now use app.timeutil.utcnow(), which returns naive UTC via the non-deprecated API. Semantics are unchanged on purpose: every datetime column is TIMESTAMP WITHOUT TIME ZONE, so going aware here would poison naive/aware comparisons. The TIMESTAMPTZ migration (Phase 2) now has a single place to change. (BE-01) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from datetime import datetime
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlmodel import Session, select
|
|
|
|
from app.auth import get_current_user
|
|
from app.db import get_session
|
|
from app.timeutil import utcnow
|
|
from app.models.models import Account, AccountCreate, AccountRead, AccountUpdate
|
|
|
|
router = APIRouter(prefix="/accounts", tags=["accounts"])
|
|
|
|
|
|
@router.get("/", response_model=list[AccountRead])
|
|
def list_accounts(
|
|
session: Session = Depends(get_session),
|
|
_user: str = Depends(get_current_user),
|
|
):
|
|
return session.exec(select(Account)).all()
|
|
|
|
|
|
@router.post("/", response_model=AccountRead, status_code=201)
|
|
def create_account(
|
|
data: AccountCreate,
|
|
session: Session = Depends(get_session),
|
|
_user: str = Depends(get_current_user),
|
|
):
|
|
account = Account.model_validate(data)
|
|
session.add(account)
|
|
session.commit()
|
|
session.refresh(account)
|
|
return account
|
|
|
|
|
|
@router.patch("/{account_id}", response_model=AccountRead)
|
|
def update_account(
|
|
account_id: int,
|
|
data: AccountUpdate,
|
|
session: Session = Depends(get_session),
|
|
_user: str = Depends(get_current_user),
|
|
):
|
|
account = session.get(Account, account_id)
|
|
if not account:
|
|
raise HTTPException(status_code=404, detail="Account not found")
|
|
update_data = data.model_dump(exclude_unset=True)
|
|
for key, value in update_data.items():
|
|
setattr(account, key, value)
|
|
account.updated_at = utcnow()
|
|
session.add(account)
|
|
session.commit()
|
|
session.refresh(account)
|
|
return account
|