Esempio n. 1
0
func getRecipesHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	service := NewService(c)

	recipes := service.FetchRecipes()
	response.WriteJson(w, recipes)
}
Esempio n. 2
0
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)
}
Esempio n. 3
0
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)
}
Esempio n. 4
0
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)
}
Esempio n. 5
0
func navHandler(w http.ResponseWriter, r *http.Request) {
	items := [1]Nav{Nav{Route: "/", Name: "Home"}}
	response.WriteJson(w, items)
}