summaryrefslogtreecommitdiff
path: root/view/recipe.go
blob: 1dd6045f18797a416b39ea03dd6af8365d8595e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package view

import (
	"net/http"

	"xengineering.eu/ceres/model"

	"github.com/gorilla/mux"
)

func Recipe(w http.ResponseWriter, r *http.Request) {
	recipe := model.Recipe{}
	recipe.Id = mux.Vars(r)[`id`]

	err := recipe.Read()
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	tmpl := "recipe"
	edit, ok := r.URL.Query()["edit"]
	if ok && len(edit) == 1 && edit[0] == "true" {
		tmpl = "recipe-edit"
	}

	err = html.ExecuteTemplate(w, tmpl, recipe)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
}