in go-rest-demo/cmd/gin/main.go [91:113]
func (h RecipesHandler) UpdateRecipe(c *gin.Context) {
// Get request body and convert it to recipes.Recipe
var recipe recipes.Recipe
if err := c.ShouldBindJSON(&recipe); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
id := c.Param("id")
err := h.store.Update(id, recipe)
if err != nil {
if err == recipes.NotFoundErr {
c.JSON(http.StatusNotFound, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
// return success payload
c.JSON(http.StatusOK, gin.H{"status": "success"})
}