2026-10-16 22:46:56 -06:00
|
|
|
"""The shop screens: the supervisor board, the stations a person may work at, and the stall board.
|
|
|
|
|
|
|
|
|
|
Any signed-in session reads them; the board answers 403 for someone who leads no department. They read
|
|
|
|
|
PostgreSQL only.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
2026-10-18 15:08:34 -06:00
|
|
|
from fastapi import APIRouter, Depends, Query, Request
|
2026-10-16 22:46:56 -06:00
|
|
|
|
2026-10-18 15:08:34 -06:00
|
|
|
from ..domain import packets, search, shop
|
2026-10-16 22:46:56 -06:00
|
|
|
from ..text import clean_text
|
|
|
|
|
from .deps import Db, Principal, current_principal, get_db
|
2026-10-18 15:08:34 -06:00
|
|
|
from .packets import FIND, site_today
|
2026-10-16 22:46:56 -06:00
|
|
|
|
|
|
|
|
router = APIRouter(prefix="/api/shop", tags=["shop"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/board")
|
|
|
|
|
def board(
|
2026-10-18 15:08:34 -06:00
|
|
|
request: Request,
|
2026-10-16 22:46:56 -06:00
|
|
|
p: Principal = Depends(current_principal), # noqa: B008
|
|
|
|
|
d: Db = Depends(get_db), # noqa: B008
|
2026-10-18 15:08:34 -06:00
|
|
|
find: dict[str, Any] = FIND,
|
2026-10-16 22:46:56 -06:00
|
|
|
project_id: int | None = Query(None),
|
|
|
|
|
unit_id: int | None = Query(None),
|
|
|
|
|
) -> dict[str, Any]:
|
2026-10-18 15:08:34 -06:00
|
|
|
"""The supervisor board. `dept` picks one of the departments the person leads (it scopes the board and its
|
|
|
|
|
KPIs); the other find bar values narrow the cards."""
|
2026-10-16 22:46:56 -06:00
|
|
|
conn = d.conn
|
|
|
|
|
pp = packets.policy_principal_for(conn, p)
|
2026-10-18 15:08:34 -06:00
|
|
|
dept = clean_text(find.get("dept") or "", 10) or None
|
|
|
|
|
filters = search.parse_filters(
|
|
|
|
|
{**find, "dept": None, "project_id": project_id, "unit_id": unit_id},
|
|
|
|
|
pp,
|
|
|
|
|
screen="supervisor",
|
|
|
|
|
today=site_today(request),
|
|
|
|
|
)
|
|
|
|
|
return shop.board(conn, pp, dept=dept, project_id=project_id, unit_id=unit_id, filters=filters)
|
2026-10-16 22:46:56 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/stations")
|
|
|
|
|
def stations(
|
|
|
|
|
p: Principal = Depends(current_principal), # noqa: B008
|
|
|
|
|
d: Db = Depends(get_db), # noqa: B008
|
|
|
|
|
) -> list[dict[str, Any]]:
|
|
|
|
|
conn = d.conn
|
|
|
|
|
return shop.stations_for(conn, packets.policy_principal_for(conn, p))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/stall")
|
|
|
|
|
def stall(
|
2026-10-18 15:08:34 -06:00
|
|
|
request: Request,
|
2026-10-16 22:46:56 -06:00
|
|
|
p: Principal = Depends(current_principal), # noqa: B008
|
|
|
|
|
d: Db = Depends(get_db), # noqa: B008
|
|
|
|
|
station_id: int = Query(ge=1),
|
2026-10-18 15:08:34 -06:00
|
|
|
find: dict[str, Any] = FIND,
|
2026-10-16 22:46:56 -06:00
|
|
|
) -> dict[str, Any]:
|
2026-10-18 15:08:34 -06:00
|
|
|
"""The cards at one station. The find bar values narrow them; `station_id` here is the stall's station, so the
|
|
|
|
|
Station filter does not apply. Mine is the station's own work."""
|
2026-10-16 22:46:56 -06:00
|
|
|
conn = d.conn
|
2026-10-18 15:08:34 -06:00
|
|
|
pp = packets.policy_principal_for(conn, p)
|
|
|
|
|
raw = {**find, "station_id": None, "mine_station_id": find.get("mine_station_id") or station_id}
|
|
|
|
|
filters = search.parse_filters(raw, pp, screen="stall", today=site_today(request))
|
|
|
|
|
return shop.stall(conn, pp, station_id, filters)
|