update recipe modal

This commit is contained in:
Kenta420-Poom 2023-09-27 13:50:53 +07:00
parent 2b0590709c
commit ac45ca47d5
4 changed files with 110 additions and 12 deletions

View file

@ -67,6 +67,25 @@ func (rr *RecipeRouter) Route(r chi.Router) {
})
})
r.Get("/{id}", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
id, err := strconv.ParseUint(chi.URLParam(r, "id"), 10, 64)
if err != nil {
http.Error(w, "Invalid ID", http.StatusBadRequest)
return
}
recipe := rr.data.GetRecipe01()
for _, v := range recipe {
if uint64(v.ID) == id {
json.NewEncoder(w).Encode(v)
return
}
}
http.Error(w, "Recipe not found", http.StatusNotFound)
})
r.Get("/json", func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Content-Type", "application/json")
json.NewEncoder(w).Encode(rr.data.GetRecipe())