From 101dd0bcc692599b1551dd572096bee11742b646 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Wed, 30 Mar 2022 22:07:35 +0200 Subject: [PATCH] adding recipes now works --- controller/backend.sh | 33 ++++++++++++++++ data/recipes.sh | 37 ++++++++++++++++++ shochu | 2 +- templates/backend.fragment.templ | 4 +- templates/backend.new.fragment.templ | 56 ++++++++++++++++++++++++++++ 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 templates/backend.new.fragment.templ diff --git a/controller/backend.sh b/controller/backend.sh index 8f60e49..e48ce4e 100644 --- a/controller/backend.sh +++ b/controller/backend.sh @@ -10,3 +10,36 @@ backendHome() { content="$(getRecipesByUsername "$username" | template "templates/backend.fragment.templ")" template "templates/layout.html.templ" } + +route GET "/backend/new" backendNew +backendNew() { + requireLoggedIn + htmlContent + endHeaders + + title="Backend - New" + content="$(template "templates/backend.new.fragment.templ")" + template "templates/layout.html.templ" +} + +route POST "/backend/new" backendAdd +backendAdd() { + requireLoggedIn + cacheFormData + + name="$(formData "name")" + description="$(formData "description")" + qts="$(formData "qts")" + ingredients="$(formData "ingredients")" + + if test "$(echo "$qts" | wc -l)" -ne "$(echo "$ingredients" | wc -l)"; then + status 400 + endHeaders + return + fi + + addRecipe "$name" "$description" "$username" "$qts" "$ingredients" + + redirect "/backend" + endHeaders +} diff --git a/data/recipes.sh b/data/recipes.sh index 50bac91..e84ec54 100644 --- a/data/recipes.sh +++ b/data/recipes.sh @@ -14,3 +14,40 @@ getRecipesByUsername() { users.username = '$(escape "$username")' EOF } + +addRecipe() { + local name="$1" + local description="$2" + local username="$3" + local qts="$4" + local ingredients="$5" + + local nrIngredients="$(echo "$qts" | wc -l)" + + template <(cat <Hi -You are {{ print $username }}. +You are {{ print $username }}.
+ +New Recipe