diff options
| author | xengineering <me@xengineering.eu> | 2024-01-17 20:56:33 +0100 | 
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2024-01-17 21:03:36 +0100 | 
| commit | 34fa1017a697287540d92d8c36ecca988f936f16 (patch) | |
| tree | 53d28064e51310c1d4e0a2617f35a81f24906498 | |
| parent | 644ddcde14c0545dd667eaf096dadab518ad90a7 (diff) | |
| download | ceres-34fa1017a697287540d92d8c36ecca988f936f16.tar ceres-34fa1017a697287540d92d8c36ecca988f936f16.tar.zst ceres-34fa1017a697287540d92d8c36ecca988f936f16.zip  | |
Add recipe step view
This is the next increment to implement recipe steps.
| -rw-r--r-- | main.go | 3 | ||||
| -rw-r--r-- | model/recipe_step.go | 33 | ||||
| -rw-r--r-- | model/sql/recipe-step-select.sql | 2 | ||||
| -rw-r--r-- | view/html/recipe-step.html | 17 | 
4 files changed, 55 insertions, 0 deletions
@@ -49,6 +49,9 @@ func startServer(addr string) *http.Server {  	r.HandleFunc("/recipes/{id}/edit", view.RecipeEditHandler).Methods(`GET`)  	r.HandleFunc("/recipes/{id}", controller.RecipePost).Methods(`POST`) +	r.HandleFunc("/recipes/{id}/steps/{step_id}", +	             view.HandlerHTML(&model.RecipeStep{})).Methods(`GET`) +  	r.HandleFunc("/", view.HandlerHTML(&model.Index{})).Methods(`GET`)  	muxer := http.NewServeMux() diff --git a/model/recipe_step.go b/model/recipe_step.go new file mode 100644 index 0000000..980d312 --- /dev/null +++ b/model/recipe_step.go @@ -0,0 +1,33 @@ +package model + +import ( +	"log" +) + +type RecipeStep struct { +	Id       string  // FIXME has to be uint +	RecipeId string  // FIXME has to be uint +	Index    string  // FIXME has to be uint +	Text     string +} + +func (d *RecipeStep) String() string { +	return d.Text +} + +func (d *RecipeStep) FromDB() error { +	query, err := GetSql(`recipe-step-select`) +	if err != nil { +		return err +	} + +	err = db.QueryRow(query, d.Id).Scan( +		&d.Id, +		&d.RecipeId, +		&d.Index, +		&d.Text, +	) + +	log.Printf("d.Text: %s %s %s %s\n", d.Id, d.RecipeId, d.Index, d.Text) +	return err +} diff --git a/model/sql/recipe-step-select.sql b/model/sql/recipe-step-select.sql new file mode 100644 index 0000000..0aba980 --- /dev/null +++ b/model/sql/recipe-step-select.sql @@ -0,0 +1,2 @@ +SELECT id,recipe_id,"index",text FROM recipe_steps +WHERE id=?; diff --git a/view/html/recipe-step.html b/view/html/recipe-step.html new file mode 100644 index 0000000..4d35e91 --- /dev/null +++ b/view/html/recipe-step.html @@ -0,0 +1,17 @@ +{{define "recipestep"}} +<html> +	{{ template "head" }} +	<header> +		<nav> +			<a href="/">HOME</a> +		</nav> +		<h1>Recipe step</h1> +	</header> +	<body> +		<main> +			<p>{{.Text}}</p> +		</main> +		{{ template "footer" }} +	</body> +</html> +{{end}}  | 
