- Register tools
- Tools in stock
Load data["rows"] (pairs of tag and qty) into an in-memory table items (tag TEXT PRIMARY KEY, qty INTEGER) with executemany. GET /tools?min_qty=N returns {"items": [{"tag": ..., "qty": ...}]} for rows with qty >= N, ordered by tag. min_qty is a required integer.
- Adjust tool counts
Load data["rows"] into items (tag TEXT PRIMARY KEY, qty INTEGER). PATCH /tools/{tag} accepts {"qty": int} and updates that row. Use cursor.rowcount to return 404 Missing when no row changed; otherwise return {"tag": ..., "qty": ...}. GET /tools returns {"items": [[tag, qty], ...]} ordered by tag.
- Loans summary
Load data["rows"] into items (tag TEXT, qty INTEGER). GET /loans/summary returns {"total": ..., "rows": ...}: the sum of qty and the row count. An empty table must report {"total": 0, "rows": 0}, not null.
- Unique member cards
Create items (card TEXT PRIMARY KEY). POST /members accepts {"card": str} and inserts it inside with conn:. A duplicate key raises sqlite3.IntegrityError; turn it into 409 with detail "Duplicate". Success returns 201 with {"card": ...}. GET /members returns {"items": [...]} ordered by key.
- Move tools between bays
Load data["bins"] into bins (name TEXT PRIMARY KEY, qty INTEGER). POST /bays/moves accepts {"source": str, "target": str, "qty": int}. In one with conn: block, subtract from the source and add to the target. Raise 409 Short when the source has less than qty, and 404 Missing when either bin does not exist; either error must leave both bins unchanged. Success returns 201 with {"moved": qty}. GET /bins returns {"bins": [[name, qty], ...]} ordered by name.
- Import a delivery note
Create items (item TEXT PRIMARY KEY, qty INTEGER CHECK (qty >= 0)). POST /deliveries accepts {"items": [{"item": str, "qty": int}]} and inserts every item in one with conn: block. Any duplicate or negative quantity raises sqlite3.IntegrityError: return 409 with detail "Rejected" and store none of that batch. Success returns 201 with {"inserted": n}. GET /deliveries lists [item, qty] pairs ordered by key.
- Retry-safe deposits
POST /deposits accepts {"amount": int} and an Idempotency-Key header. A missing key returns 400 with detail "Missing key". Store each new key with its amount in requests (key TEXT PRIMARY KEY, amount INTEGER) and return 201 with {"key": ..., "amount": ..., "replayed": False}. A repeated key returns 200 with the stored amount and "replayed": True, even when the new body differs.