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.access.check import holds
|
||||
from core.timeutil import utcnow
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Body
|
||||
from fastapi import APIRouter, Depends, status, Body
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
from datetime import datetime, timezone, timedelta
|
||||
@@ -34,7 +34,7 @@ def list_groups(db: Session = Depends(get_db), user: User = Depends(get_current_
|
||||
@router.post("/groups", response_model=TableGroupOut, status_code=status.HTTP_201_CREATED)
|
||||
def create_group(body: TableGroupCreate, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
if db.query(TableGroup).filter(TableGroup.name == body.name).first():
|
||||
raise HTTPException(status_code=400, detail="Group name already exists")
|
||||
raise XeniaError("table_group.name_taken")
|
||||
sort_order = db.query(TableGroup).count()
|
||||
group = TableGroup(name=body.name, prefix=body.prefix, color=body.color, sort_order=sort_order)
|
||||
db.add(group)
|
||||
@@ -54,7 +54,7 @@ def reorder_groups(body: List[int] = Body(...), db: Session = Depends(get_db), u
|
||||
def update_group(group_id: int, body: TableGroupUpdate, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
group = db.query(TableGroup).filter(TableGroup.id == group_id).first()
|
||||
if not group:
|
||||
raise HTTPException(status_code=404, detail="Group not found")
|
||||
raise XeniaError("table_group.not_found")
|
||||
for field, value in body.model_dump(exclude_none=True).items():
|
||||
setattr(group, field, value)
|
||||
db.commit()
|
||||
@@ -66,7 +66,7 @@ def update_group(group_id: int, body: TableGroupUpdate, db: Session = Depends(ge
|
||||
def delete_group(group_id: int, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
group = db.query(TableGroup).filter(TableGroup.id == group_id).first()
|
||||
if not group:
|
||||
raise HTTPException(status_code=404, detail="Group not found")
|
||||
raise XeniaError("table_group.not_found")
|
||||
db.query(Table).filter(Table.group_id == group_id).update({"group_id": None})
|
||||
db.delete(group)
|
||||
db.commit()
|
||||
@@ -149,7 +149,7 @@ def create_table(body: TableCreate, db: Session = Depends(get_db), user: User =
|
||||
@router.post("/batch", response_model=List[TableOut], status_code=status.HTTP_201_CREATED)
|
||||
def batch_create_tables(body: TableBatchCreate, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
if body.count < 1 or body.count > 200:
|
||||
raise HTTPException(status_code=400, detail="Count must be between 1 and 200")
|
||||
raise XeniaError("validation.range", field='count', min=1, max=200)
|
||||
|
||||
# Group-local label numbering: find highest suffix already used in this group
|
||||
existing_in_group = (
|
||||
@@ -171,10 +171,7 @@ def batch_create_tables(body: TableBatchCreate, db: Session = Depends(get_db), u
|
||||
last_n = start_label_n + body.count - 1
|
||||
worst_case = f"{body.name_prefix}{last_n}"
|
||||
if len(worst_case) > MAX_TABLE_NAME_LENGTH:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail=f"Table name '{worst_case}' would exceed {MAX_TABLE_NAME_LENGTH} characters. Shorten the prefix or reduce the count.",
|
||||
)
|
||||
raise XeniaError("table.name_too_long", name=worst_case, max=MAX_TABLE_NAME_LENGTH)
|
||||
|
||||
created = []
|
||||
for i in range(body.count):
|
||||
@@ -199,7 +196,7 @@ def batch_create_tables(body: TableBatchCreate, db: Session = Depends(get_db), u
|
||||
def update_table(table_id: int, body: TableUpdate, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
table = db.query(Table).filter(Table.id == table_id).first()
|
||||
if not table:
|
||||
raise HTTPException(status_code=404, detail="Table not found")
|
||||
raise XeniaError("table.not_found")
|
||||
for field, value in body.model_dump(exclude_none=True).items():
|
||||
setattr(table, field, value)
|
||||
db.commit()
|
||||
@@ -211,16 +208,13 @@ def update_table(table_id: int, body: TableUpdate, db: Session = Depends(get_db)
|
||||
def delete_table(table_id: int, hard: bool = False, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
table = db.query(Table).filter(Table.id == table_id).first()
|
||||
if not table:
|
||||
raise HTTPException(status_code=404, detail="Table not found")
|
||||
raise XeniaError("table.not_found")
|
||||
active_order = db.query(Order).filter(
|
||||
Order.table_id == table_id,
|
||||
Order.status.in_(["open", "partially_paid", "paid"])
|
||||
).first()
|
||||
if active_order:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Cannot delete or deactivate a table with an active order"
|
||||
)
|
||||
raise XeniaError("table.has_order")
|
||||
if hard:
|
||||
# Delete all past (non-active) orders for this table so FK constraint doesn't block deletion.
|
||||
# Active orders are already blocked above. Items/waiters/print_logs cascade via ORM.
|
||||
@@ -238,7 +232,7 @@ def delete_table(table_id: int, hard: bool = False, db: Session = Depends(get_db
|
||||
def table_status(table_id: int, db: Session = Depends(get_db), user: User = Depends(get_current_user)):
|
||||
table = db.query(Table).filter(Table.id == table_id).first()
|
||||
if not table:
|
||||
raise HTTPException(status_code=404, detail="Table not found")
|
||||
raise XeniaError("table.not_found")
|
||||
active_order = (
|
||||
db.query(Order)
|
||||
.filter(Order.table_id == table_id, Order.status.in_(["open", "partially_paid", "paid"]))
|
||||
@@ -255,7 +249,7 @@ def table_status(table_id: int, db: Session = Depends(get_db), user: User = Depe
|
||||
def update_floorplan(table_id: int, body: TableFloorplanUpdate, db: Session = Depends(get_db), user: User = Depends(require_tables_manager)):
|
||||
table = db.query(Table).filter(Table.id == table_id).first()
|
||||
if not table:
|
||||
raise HTTPException(status_code=404, detail="Table not found")
|
||||
raise XeniaError("table.not_found")
|
||||
table.floor_x = body.floor_x
|
||||
table.floor_y = body.floor_y
|
||||
db.commit()
|
||||
@@ -276,6 +270,7 @@ def _table_in_zones(db: Session, user: User, table: Table) -> bool:
|
||||
|
||||
from core.access.deps import require as _require # noqa: E402
|
||||
from core.modules.state import module_required as _module_required # noqa: E402
|
||||
from core.errors import XeniaError
|
||||
|
||||
|
||||
@router.get("/{table_id}/history", dependencies=[Depends(_module_required("history"))])
|
||||
|
||||
Reference in New Issue
Block a user