update recipe modal
This commit is contained in:
parent
2b0590709c
commit
ac45ca47d5
4 changed files with 110 additions and 12 deletions
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue