From 155c499c1707ceb0eff4223d57bc562cb5437dc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Albert=20Esp=C3=ADn?= Date: Sun, 2 Mar 2025 14:27:10 +0100 Subject: [PATCH] product modification --- internal/handlers/product.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/internal/handlers/product.go b/internal/handlers/product.go index 44db980..fc12f01 100644 --- a/internal/handlers/product.go +++ b/internal/handlers/product.go @@ -1,6 +1,7 @@ package handlers import ( + "encoding/json" "net/http" "git.espin.casa/albert/mercadona/internal/client" @@ -9,6 +10,20 @@ import ( func GetMercadonaProduct(client client.IMercadona) httprouter.Handle { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { - + id := p.ByName("id") + product, err := client.GetMercadonaProduct(r.Context(), id) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + // marshal product + resp, err := json.Marshal(&product) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } + w.WriteHeader(http.StatusOK) + w.Header().Add("application/type", "application/json") + if _, err = w.Write(resp); err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } }