fixed remove issue, made items avaiable for available view

This commit is contained in:
2026-11-12 12:49:19 -07:00
parent 2807ffd160
commit 120daf8c31
10 changed files with 445 additions and 27 deletions

View File

@@ -116,11 +116,22 @@ The inventory view can be filtered by category and searched by name/class
name, and sorted by `name` (default), `category`, `quantity` (high to low) or
`updated` (most recently changed first).
Inventory rows store `(user_id, class_name, quantity, notes)`. Adding an item
that is already present increments its quantity; quantity and notes can then be
edited or the row removed. Responses are enriched live from the catalog. If a
catalog item disappears after a dataset refresh, the row is reported with
`available: false` instead of being silently deleted.
Inventory rows store `(user_id, class_name, quantity, notes, visibility)`.
Adding an item that is already present increments its quantity; quantity, notes
and visibility can then be edited or the row removed. Every added item starts
`private`; the Visibility toggle switches it to `available` and back. Responses
are enriched live from the catalog. If a catalog item disappears after a
dataset refresh, the row is reported with `available: false` instead of being
silently deleted (`available` is about the catalog, `visibility` is the owner's
classification).
The **Available** tab (backed by `GET /api/v1/available`) is public, like the
catalog: it lists every row marked `available` across all accounts with the
item's catalog details, quantity, owner username and last update. Private rows
never appear there and inventory notes are never exposed.
Clicking an item name in either **My Inventory** or **Available** opens the same
catalog detail view used by the catalog grid.
### Security: read before exposing this publicly
@@ -161,7 +172,7 @@ curl -fsS -b cookies.txt http://localhost:8080/api/v1/me/inventory
cd trade-hub/backend
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt -r requirements-dev.txt
.venv/bin/python -m pytest tests/ -q # 50 tests, no database needed
.venv/bin/python -m pytest tests/ -q # 59 tests, no database needed
DATA_DIR=./data/samples .venv/bin/uvicorn main:app --port 8000
```
@@ -173,8 +184,9 @@ so no PostgreSQL server is required for the suite. Production uses PostgreSQL.
Tables are created on startup with an idempotent `create_all` and a connection
retry loop, so a fresh volume bootstraps itself and a slow PostgreSQL start does
not crash the backend. This does not migrate changed columns — introduce Alembic
when the schema starts evolving in place.
not crash the backend. Additive columns for existing deployments (currently
`inventory_entries.visibility`) are applied automatically on startup; changing
or dropping a column still requires Alembic.
## API
@@ -193,11 +205,15 @@ GET /api/v1/auth/me -> {user}
GET /api/v1/me/inventory?category=&search=&sort=&page=&page_size=
GET /api/v1/me/inventory/summary
POST /api/v1/me/inventory {class_name, quantity?, notes?}
PATCH /api/v1/me/inventory/{class_name} {quantity?, notes?}
PATCH /api/v1/me/inventory/{class_name} {quantity?, notes?, visibility?}
DELETE /api/v1/me/inventory/{class_name}
GET /api/v1/available?category=&search=&sort=&page=&page_size=
```
`/api/v1/me/*` requires a valid session cookie and returns `401` otherwise.
`/api/v1/available` is public and read-only; it accepts `sort=name|category|quantity|updated`
(default `updated`).
### Configuration