feat: location hierarchy CRUD API #81

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

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

Database tables exist (locations table in migrations/001_initial.sql) but no repository layer, routes, or handlers are implemented.

Database schema (already exists):

CREATE TABLE locations (
    id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    path TEXT UNIQUE NOT NULL,  -- e.g., 'lab/shelf-a/bin-3'
    name TEXT NOT NULL,
    parent_id UUID REFERENCES locations(id),
    location_type TEXT NOT NULL,
    depth INTEGER NOT NULL DEFAULT 0,
    metadata JSONB DEFAULT '{}',
    created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

Tasks:

  • Create internal/db/locations.go — repository with CRUD methods, hierarchy traversal
  • Create internal/api/location_handlers.go — HTTP handlers
  • Register routes in internal/api/routes.go:
    • GET /api/locations ��� list locations (flat or tree)
    • POST /api/locations — create location
    • GET /api/locations/{path} — get location by path
    • DELETE /api/locations/{path} — delete location (reject if inventory exists)
  • Add tests for repository and handlers
  • Support parent_id for nested hierarchy and depth auto-calculation

Related: #56 (broader inventory-location model issue)

**Ref:** `docs/ROADMAP.md` § Appendix B / 1.6 Location & Inventory APIs Database tables exist (`locations` table in `migrations/001_initial.sql`) but no repository layer, routes, or handlers are implemented. **Database schema (already exists):** ```sql CREATE TABLE locations ( id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), path TEXT UNIQUE NOT NULL, -- e.g., 'lab/shelf-a/bin-3' name TEXT NOT NULL, parent_id UUID REFERENCES locations(id), location_type TEXT NOT NULL, depth INTEGER NOT NULL DEFAULT 0, metadata JSONB DEFAULT '{}', created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); ``` **Tasks:** - [ ] Create `internal/db/locations.go` — repository with CRUD methods, hierarchy traversal - [ ] Create `internal/api/location_handlers.go` — HTTP handlers - [ ] Register routes in `internal/api/routes.go`: - `GET /api/locations` ��� list locations (flat or tree) - `POST /api/locations` — create location - `GET /api/locations/{path}` — get location by path - `DELETE /api/locations/{path}` — delete location (reject if inventory exists) - [ ] Add tests for repository and handlers - [ ] Support `parent_id` for nested hierarchy and `depth` auto-calculation Related: #56 (broader inventory-location model issue)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/silo#81