package web import ( "fmt" "net/http" "net/url" ) // handleScan resolves a scanned or printed asset tag (the payload of a // label's QR code) and redirects into the inventory page with that asset // selected. Scanning with a phone camera opens this URL directly; a USB // barcode scanner focused on the browser's address bar works the same way. func (a *App) handleScan(w http.ResponseWriter, r *http.Request) { tag := r.PathValue("tag") asset, err := a.Assets.GetByTag(r.Context(), tag) if err != nil { http.Redirect(w, r, "/inventory?scan_error="+url.QueryEscape(tag), http.StatusSeeOther) return } http.Redirect(w, r, fmt.Sprintf("/inventory?asset=%d", asset.ID), http.StatusSeeOther) }