feat: foundations for the manager conversion (platform-v2 step 6.1)
- Backend: every HTTPException in routers/ is an error code now (260 raises, ~105 new codes, texts in en + el); XeniaError(detail=...) keeps the three v1-shaped answers old pages read; bad / unknown tokens answer auth.session_ended; test_errors refuses new HTTPExceptions. - Manager: v2.json is the list of pages on the v2 rules: scripts/lint.mjs lints them, tests/v2-guards.test.mjs refuses Greek and colour literals, `strict` paths make set-state-in-effect an error. - src/live/useLiveQuery.js (react-query + live events + refresh on reconnect); Signed in now uses it. - Dead manager files removed (3.1k lines unreachable from main.jsx). - Tests: backend 544 passed, manager unit 33, run-all (no Android) passed (manager's live bell check passed on a rerun). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from core.timeutil import utcnow
|
||||
from datetime import datetime, timezone
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Query
|
||||
from fastapi import APIRouter, Depends, status, Query
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
|
||||
@@ -13,6 +13,7 @@ from schemas.expenses import (
|
||||
ExpensePaymentCreate, ExpensePaymentOut,
|
||||
)
|
||||
from routers.deps import require_manager
|
||||
from core.errors import XeniaError
|
||||
|
||||
contacts_router = APIRouter()
|
||||
expenses_router = APIRouter()
|
||||
@@ -97,7 +98,7 @@ def create_contact(body: ContactCreate, db: Session = Depends(get_db), user: Use
|
||||
def update_contact(contact_id: int, body: ContactUpdate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
|
||||
contact = db.query(Contact).filter(Contact.id == contact_id).first()
|
||||
if not contact:
|
||||
raise HTTPException(status_code=404, detail="Contact not found")
|
||||
raise XeniaError("contact.not_found")
|
||||
for field, value in body.model_dump(exclude_none=True).items():
|
||||
setattr(contact, field, value)
|
||||
db.commit()
|
||||
@@ -109,7 +110,7 @@ def update_contact(contact_id: int, body: ContactUpdate, db: Session = Depends(g
|
||||
def delete_contact(contact_id: int, db: Session = Depends(get_db), user: User = Depends(require_manager)):
|
||||
contact = db.query(Contact).filter(Contact.id == contact_id).first()
|
||||
if not contact:
|
||||
raise HTTPException(status_code=404, detail="Contact not found")
|
||||
raise XeniaError("contact.not_found")
|
||||
contact.is_active = False
|
||||
db.commit()
|
||||
|
||||
@@ -174,7 +175,7 @@ def create_expense(body: ExpenseCreate, db: Session = Depends(get_db), user: Use
|
||||
def update_expense(expense_id: int, body: ExpenseUpdate, db: Session = Depends(get_db), user: User = Depends(require_manager)):
|
||||
expense = db.query(Expense).filter(Expense.id == expense_id).first()
|
||||
if not expense:
|
||||
raise HTTPException(status_code=404, detail="Expense not found")
|
||||
raise XeniaError("expense.not_found")
|
||||
for field, value in body.model_dump(exclude_none=True).items():
|
||||
setattr(expense, field, value)
|
||||
db.commit()
|
||||
@@ -186,7 +187,7 @@ def update_expense(expense_id: int, body: ExpenseUpdate, db: Session = Depends(g
|
||||
def delete_expense(expense_id: int, db: Session = Depends(get_db), user: User = Depends(require_manager)):
|
||||
expense = db.query(Expense).filter(Expense.id == expense_id).first()
|
||||
if not expense:
|
||||
raise HTTPException(status_code=404, detail="Expense not found")
|
||||
raise XeniaError("expense.not_found")
|
||||
db.delete(expense)
|
||||
db.commit()
|
||||
|
||||
@@ -200,9 +201,9 @@ def record_payment(
|
||||
):
|
||||
expense = db.query(Expense).filter(Expense.id == expense_id).first()
|
||||
if not expense:
|
||||
raise HTTPException(status_code=404, detail="Expense not found")
|
||||
raise XeniaError("expense.not_found")
|
||||
if body.amount <= 0:
|
||||
raise HTTPException(status_code=400, detail="Payment amount must be positive")
|
||||
raise XeniaError("validation.positive", field='amount')
|
||||
payment = ExpensePayment(
|
||||
expense_id=expense_id,
|
||||
amount=body.amount,
|
||||
|
||||
Reference in New Issue
Block a user