diff options
| -rw-r--r-- | controller/recipe.go | 3 | ||||
| -rw-r--r-- | view/html/nav.html | 1 | ||||
| -rw-r--r-- | view/html/recipe.html | 1 | ||||
| -rw-r--r-- | view/static/ceres.js | 17 | 
4 files changed, 21 insertions, 1 deletions
diff --git a/controller/recipe.go b/controller/recipe.go index a2e5ab6..818a077 100644 --- a/controller/recipe.go +++ b/controller/recipe.go @@ -12,6 +12,7 @@ import (  func RecipeCreate(w http.ResponseWriter, r *http.Request) {  	recipe := model.Recipe{} +	recipe.Title = "recipe without title"  	err := recipe.Create()  	if err != nil { @@ -19,7 +20,7 @@ func RecipeCreate(w http.ResponseWriter, r *http.Request) {  		return  	} -	http.Redirect(w, r, "/recipe/" + recipe.Id, http.StatusSeeOther) +	http.Redirect(w, r, "/recipe/" + recipe.Id + "?view=recipe-edit", http.StatusSeeOther)  }  func RecipeUpdate(w http.ResponseWriter, r *http.Request) { diff --git a/view/html/nav.html b/view/html/nav.html index 7bc0206..9da1b6b 100644 --- a/view/html/nav.html +++ b/view/html/nav.html @@ -1,5 +1,6 @@  {{define "nav"}}  		<nav>  			<a href="/recipes">HOME</a> +			<a onclick="create('/recipe')">add recipe</a>  		</nav>  {{end}} diff --git a/view/html/recipe.html b/view/html/recipe.html index 04230ea..bce4ffa 100644 --- a/view/html/recipe.html +++ b/view/html/recipe.html @@ -15,6 +15,7 @@  			<a href="/recipe/{{.Id}}?view=recipe-confirm-deletion"><button style="background-color:red">delete</button></a>  		</main>  		{{ template "footer" }} +		<script src="/static/view/static/ceres.js"></script>  	</body>  </html>  {{end}} diff --git a/view/static/ceres.js b/view/static/ceres.js index 3bfeb6c..2fff18c 100644 --- a/view/static/ceres.js +++ b/view/static/ceres.js @@ -31,6 +31,23 @@ function updateFormData(event) {  	});  } +function create(url) { +	fetch(url, {method: 'POST'}) +	.then(response => { +		if (response.ok) { +			console.log('Create successfully'); +		} else { +			console.error('Create failed'); +		} +		if (response.redirected) { +			window.location.href = response.url; +		} +	}) +	.catch(error => { +		console.error('Network error:', error); +	}); +} +  function del(url) {  	fetch(url, {method: 'DELETE'})  	.then(response => {  | 
