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