func getRecipesHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) service := NewService(c) recipes := service.FetchRecipes() response.WriteJson(w, recipes) }
func getRecipeHandler(w http.ResponseWriter, r *http.Request) { recipeId := getRecipeId(r) c := appengine.NewContext(r) service := NewService(c) recipe := service.FetchRecipe(recipeId) response.WriteJson(w, recipe) }
func addImageHandler(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) fileStore := context.NewFileStore(c) _, imageKey := fileStore.GetUploadedFileKey(r, "file") service := NewService(c) recipeId := getRecipeId(r) service.AddImageToRecipe(recipeId, imageKey) img := Image{serveImageRoute(imageKey)} response.WriteJson(w, img) }
func createRecipeHandler(w http.ResponseWriter, r *http.Request) { var recipe Recipe response.DecodeJson(r.Body, &recipe) c := appengine.NewContext(r) service := NewService(c) recipeModel, err := service.Add(&recipe) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } response.WriteJson(w, recipeModel) }
func navHandler(w http.ResponseWriter, r *http.Request) { items := [1]Nav{Nav{Route: "/", Name: "Home"}} response.WriteJson(w, items) }