product modification

This commit is contained in:
Albert Espín 2025-03-02 14:27:10 +01:00
parent 5b34f8fae3
commit 155c499c17

View File

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