feat: inventory tracking API #82

Open
opened 2026-02-13 19:03:52 +00:00 by forbes · 0 comments
Owner

Ref: docs/ROADMAP.md § Appendix B / 1.6 Location & Inventory APIs

Database table exists (inventory table in migrations/001_initial.sql) but no repository layer, routes, or handlers are implemented. Depends on #81 (location CRUD).

Database schema (already exists):

CREATE TABLE inventory (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    item_id UUID NOT NULL REFERENCES items(id) ON DELETE CASCADE,
    location_id UUID NOT NULL REFERENCES locations(id) ON DELETE CASCADE,
    quantity DECIMAL(12, 4) NOT NULL DEFAULT 0,
    updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
    UNIQUE(item_id, location_id)
);

Tasks:

  • Create internal/db/inventory.go — repository with query, adjust, and move methods
  • Create internal/api/inventory_handlers.go — HTTP handlers
  • Register routes in internal/api/routes.go:
    • GET /api/inventory/{partNumber} — get inventory across all locations
    • POST /api/inventory/{partNumber}/adjust — adjust quantity at a location
    • POST /api/inventory/{partNumber}/move — move quantity between locations
  • Add audit logging for inventory adjustments
  • Add tests for repository and handlers
  • Validate quantity cannot go negative on adjust/move

Related: #56 (broader inventory-location model issue), #81 (location CRUD — prerequisite)

**Ref:** `docs/ROADMAP.md` § Appendix B / 1.6 Location & Inventory APIs Database table exists (`inventory` table in `migrations/001_initial.sql`) but no repository layer, routes, or handlers are implemented. Depends on #81 (location CRUD). **Database schema (already exists):** ```sql CREATE TABLE inventory ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), item_id UUID NOT NULL REFERENCES items(id) ON DELETE CASCADE, location_id UUID NOT NULL REFERENCES locations(id) ON DELETE CASCADE, quantity DECIMAL(12, 4) NOT NULL DEFAULT 0, updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), UNIQUE(item_id, location_id) ); ``` **Tasks:** - [ ] Create `internal/db/inventory.go` — repository with query, adjust, and move methods - [ ] Create `internal/api/inventory_handlers.go` — HTTP handlers - [ ] Register routes in `internal/api/routes.go`: - `GET /api/inventory/{partNumber}` — get inventory across all locations - `POST /api/inventory/{partNumber}/adjust` — adjust quantity at a location - `POST /api/inventory/{partNumber}/move` — move quantity between locations - [ ] Add audit logging for inventory adjustments - [ ] Add tests for repository and handlers - [ ] Validate quantity cannot go negative on adjust/move Related: #56 (broader inventory-location model issue), #81 (location CRUD — prerequisite)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#82