displying recipes now works

This commit is contained in:
overflowerror 2022-03-30 22:43:32 +02:00
parent 101dd0bcc6
commit f822e73362
3 changed files with 67 additions and 0 deletions

View file

@ -9,3 +9,31 @@ home() {
content="$(template "templates/home.fragment.templ")"
template "templates/layout.html.templ"
}
route GET "/recipe" recipe
recipe() {
id="$(queryString "id")"
result="$(getRecipeById "$id")"
if test -z "$result"; then
"$_404"
return
fi
htmlContent
endHeaders
name="$(echo "$result" | head -n 1 | getColumns 1)"
description="$(echo "$result" | head -n 1 | getColumns 2)"
uid="$(echo "$result" | head -n 1 | getColumns 5)"
author="$(echo "$result" | head -n 1 | getColumns 6)"
qts="$(echo "$result" | getColumns 4)"
ingredients="$(echo "$result" | getColumns 3)"
nrIngredients="$(echo "$qts" | wc -l)"
title=""
content="$(template "templates/recipe.fragment.templ")"
template "templates/layout.html.templ"
}

View file

@ -15,6 +15,26 @@ getRecipesByUsername() {
EOF
}
getRecipeById() {
local id="$(echo "$1" | sed 's/[^0-9]//g')"
query <<EOF
SELECT
recipes.name,
description,
ingredients.name,
ingredients.quantity,
users.id,
users.username
FROM recipes
INNER JOIN ingredients
ON recipes.id = ingredients.recipeFk
INNER JOIN users
ON recipes.userFk = users.id
WHERE recipes.id = $id
EOF
}
addRecipe() {
local name="$1"
local description="$2"

View file

@ -0,0 +1,19 @@
<h1>{{ print "$name" }}</h1>
<p>
from <a href="/profile?id={{ print "$uid" }}">{{ print "$author" }}</a>
</p>
<table>
{{ for i in $(seq $nrIngredients); do }}
<tr>
<td>
{{ echo "$qts" | tail -n +$i | head -n 1 }}
</td>
<td>
{{ echo "$ingredients" | tail -n +$i | head -n 1 }}
</td>
</tr>
{{ done }}
</table>
<p>
{{ print "$description" }}
</p>