From 6555c9277a1c340f98b2e2c0d6612aa93609eaf3 Mon Sep 17 00:00:00 2001 From: Crumb Owl Date: Mon, 14 Jul 2025 21:19:57 +0000 Subject: [PATCH] ProductBarcode: use json encoder from the project --- backend/app/api/handlers/v1/v1_ctrl_product_search.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_product_search.go b/backend/app/api/handlers/v1/v1_ctrl_product_search.go index ce21b022..248cf87e 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_product_search.go +++ b/backend/app/api/handlers/v1/v1_ctrl_product_search.go @@ -12,6 +12,7 @@ import ( "time" "github.com/hay-kot/httpkit/errchain" + "github.com/hay-kot/httpkit/server" "github.com/rs/zerolog/log" "github.com/sysadminsmedia/homebox/backend/internal/data/repo" "github.com/sysadminsmedia/homebox/backend/internal/sys/config" @@ -322,14 +323,10 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC p.ImageBase64 = base64Encoding } - w.Header().Set("Content-Type", "application/json") - if len(products) != 0 { - // Return only the first result for now. Enhance this with a dedicated dialog - // displaying all the references found? - return json.NewEncoder(w).Encode(products) + return server.JSON(w, http.StatusOK, products) } - return nil + return server.JSON(w, http.StatusNoContent, nil) } }