feat(03-02): wire GET /api/inventory and GET /api/inventory/{id} routes

- NewRouter signature extended to accept *handlers.InventoryHandler
- GET /inventory and GET /inventory/{id} registered in /api route group
- main.go constructs handlers.NewInventoryHandler(nbClient) and passes to NewRouter
This commit is contained in:
Mikkel Georgsen 2026-04-10 06:15:12 +00:00
parent b0b6153b24
commit 743611f488
2 changed files with 6 additions and 2 deletions

View file

@ -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)

View file

@ -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.