diff --git a/cmd/hwlab/main.go b/cmd/hwlab/main.go index 80e7704..95a3d23 100644 --- a/cmd/hwlab/main.go +++ b/cmd/hwlab/main.go @@ -77,7 +77,8 @@ func main() { cfg.AI.QuickAddThreshold, ) - router := api.NewRouter(staticFS, intakeHandler) + inventoryHandler := handlers.NewInventoryHandler(nbClient) + router := api.NewRouter(staticFS, intakeHandler, inventoryHandler) addr := fmt.Sprintf("%s:%d", cfg.Host, cfg.Port) log.Printf("HWLab starting on %s", addr) diff --git a/internal/api/router.go b/internal/api/router.go index a5ac44b..2c8aaf4 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -33,7 +33,8 @@ func (h spaHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // NewRouter creates the chi router. staticFiles is the fs.FS rooted at web/dist, // passed from main.go where the go:embed directive lives. // intakeHandler handles POST /api/intake (multipart photo upload). -func NewRouter(staticFiles fs.FS, intakeHandler http.Handler) http.Handler { +// inventoryHandler handles GET /api/inventory and GET /api/inventory/{id}. +func NewRouter(staticFiles fs.FS, intakeHandler http.Handler, inventoryHandler *handlers.InventoryHandler) http.Handler { r := chi.NewRouter() r.Use(middleware.Logger) r.Use(middleware.Recoverer) @@ -42,6 +43,8 @@ func NewRouter(staticFiles fs.FS, intakeHandler http.Handler) http.Handler { r.Route("/api", func(r chi.Router) { r.Get("/health", handlers.Health) r.Post("/intake", intakeHandler.ServeHTTP) + r.Get("/inventory", inventoryHandler.ListInventory) + r.Get("/inventory/{id}", inventoryHandler.GetInventoryItem) }) // SPA fallback — serve static files; unknown paths fall back to index.html.