Files
PacketStation/server/packetstation/api/shop.py
T

50 lines
1.5 KiB
Python
Raw Normal View History

"""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
from fastapi import APIRouter, Depends, Query
from ..domain import packets, shop
from ..text import clean_text
from .deps import Db, Principal, current_principal, get_db
router = APIRouter(prefix="/api/shop", tags=["shop"])
@router.get("/board")
def board(
p: Principal = Depends(current_principal), # noqa: B008
d: Db = Depends(get_db), # noqa: B008
dept: str = Query("", max_length=10),
project_id: int | None = Query(None),
unit_id: int | None = Query(None),
) -> dict[str, Any]:
conn = d.conn
pp = packets.policy_principal_for(conn, p)
return shop.board(conn, pp, dept=clean_text(dept, 10) or None, project_id=project_id, unit_id=unit_id)
@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(
p: Principal = Depends(current_principal), # noqa: B008
d: Db = Depends(get_db), # noqa: B008
station_id: int = Query(ge=1),
) -> dict[str, Any]:
conn = d.conn
return shop.stall(conn, packets.policy_principal_for(conn, p), station_id)