Does not work: uploading images

Adding/Editing/Deleting works
SeasonsSelect works
Nice recipe layout
This commit is contained in:
2023-06-24 15:31:10 +02:00
parent 3d0d3f41e2
commit 9392ff6ada
25 changed files with 1150 additions and 209 deletions

View File

@ -16,7 +16,7 @@ export const POST: RequestHandler = async ({request}) => {
await dbConnect();
await Recipe.create(recipe_json);
await dbDisconnect();
return {status: 400} //TODO: cleanup error throwing
return {status: 200} //TODO: cleanup error throwing
}
else{
console.log("PASSWORD INCORRECT")

View File

@ -0,0 +1,23 @@
import type { RequestHandler } from '@sveltejs/kit';
import { Recipe } from '../../../models/Recipe';
import { dbConnect, dbDisconnect } from '../../../utils/db';
import type {RecipeModelType} from '../../../types/types';
import { BEARER_TOKEN } from '$env/static/private'
// header: use for bearer token for now
// recipe json in body
export const POST: RequestHandler = async ({request}) => {
let message = await request.json()
const short_name = message.old_short_name
const bearer_token = message.headers.bearer
if(bearer_token === BEARER_TOKEN){
console.log("PASSWORD CORRECT")
await dbConnect();
await Recipe.findOneAndDelete({short_name: short_name});
await dbDisconnect();
return {status: 400} //TODO: cleanup error throwing
}
else{
console.log("PASSWORD INCORRECT")
return {status: 403}
}
};

View File

@ -3,6 +3,7 @@ import { Recipe } from '../../../models/Recipe';
import { dbConnect, dbDisconnect } from '../../../utils/db';
import type {RecipeModelType} from '../../../types/types';
import { BEARER_TOKEN } from '$env/static/private'
import { error } from '@sveltejs/kit';
// header: use for bearer token for now
// recipe json in body
export const POST: RequestHandler = async ({request}) => {
@ -10,16 +11,15 @@ export const POST: RequestHandler = async ({request}) => {
let message = await request.json()
const recipe_json = message.recipe
const bearer_token = message.headers.bearer
console.log("RECIPE:", recipe_json)
console.log("BEARER:", bearer_token)
if(bearer_token === BEARER_TOKEN){
await dbConnect();
await Recipe.findOneAndUpdate({short_name: message.old_short_name }, recipe_json);
await dbDisconnect();
return {status: 400} //TODO: cleanup error throwing
const res = new Response(JSON.stringify({ message: "Updated Recipe successfully"}), { status: 200 })
return res
}
else{
console.log("PASSWORD INCORRECT")
return {status: 403}
console.log("INCORRECT PASSWORD")
throw error(403, "Password incorrect")
}
};

View File

@ -0,0 +1,13 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { Recipe } from '../../../../models/Recipe';
import { dbConnect, dbDisconnect } from '../../../../utils/db';
import type {BriefRecipeType} from '../../../../types/types';
export const GET: RequestHandler = async ({params}) => {
await dbConnect();
let icons = (await Recipe.distinct('icon').lean());
await dbDisconnect();
icons = JSON.parse(JSON.stringify(icons));
return json(icons);
};

View File

@ -0,0 +1,13 @@
import { json, type RequestHandler } from '@sveltejs/kit';
import { Recipe } from '../../../../../models/Recipe';
import { dbConnect, dbDisconnect } from '../../../../../utils/db';
import type {BriefRecipeType} from '../../../../../types/types';
export const GET: RequestHandler = async ({params}) => {
await dbConnect();
let recipes = (await Recipe.find({tags: params.icon}, 'name short_name images tags category icon description season').lean()) as BriefRecipeType[];
await dbDisconnect();
recipes = JSON.parse(JSON.stringify(recipes));
return json(recipes);
};

View File

@ -16,10 +16,12 @@ const test_json = [
caption: "",
}],
description: "Alles was das Bauernherz erfreuen lässt in einer Mahlzeit.",
tags: ["Schweiz", "Käse", "Speck", "Nudeln", "Apfelmuß", "Kartoffeln"],
season: [6,7,8,9,10,11,12,1],
preamble: "Dieser Schweizer Klassiker ist wohl das beste Essen nach einem langen Tag von Skifahren. Die Beilage aus Apfelmus ist ein Muss.",
tags: ["Schweiz", "Käse", "Speck", "Nudeln", "Apfelmuß", "Kartoffeln", "Fleisch"],
season: [10,11,12,1],
portions: "4 Hauptspeisen",
total_time: "30 Minuten",
preparation: "10 min",
total_time: "30 min",
ingredients: [ {
name: "",
list: [

View File

@ -0,0 +1,77 @@
const obj =
{
short_name: "aelplermagronen",
name : "Älplermagronen",
category: "Hauptspeise",
icon: "🍂",
datecreated: 20230619,
datemodified: 20230619,
images: [{
mediapath: "aelplermagronen.webp",
alt: "Älplermagronen serviert mit Apfelmuß",
caption: "",
}],
description: "Alles was das Bauernherz erfreuen lässt in einer Mahlzeit.",
tags: ["Schweiz", "Käse", "Speck", "Nudeln", "Apfelmuß", "Kartoffeln"],
season: [6,7,8,9,10,11,12,1],
portions: "4 Hauptspeisen",
total_time: "30 Minuten",
ingredients: [ {
name: "",
list: [
{ name: "Speckwürfel",
unit: "g",
amount: "150"
},
{
name: "mittelgroße Zwiebeln",
unit: "",
amount: "3",
},
{
name: "Kartoffeln, festkochend",
unit: "g",
amount: "400",
},
{
name: "Milch",
unit: "L",
amount: "1-2",
},
{
name: "Maccaroni",
unit: "g",
amount: "400",
},
{
name: "Appenzeller",
unit: "g",
amount: "150",
},
{
name: "<a href=apfelmuss>Apfelmuß</a>",
unit: "",
amount: "",
},
]},
],
instructions: [
{name: "",
steps: [
"In einem großen Topf oder tiefer Pfanne Speckwürfel anbraten.",
"Zwiebel in Halbringe schneiden und im gleichen Topf schwitzen lassen.",
"Kartoffeln schälen und in ~1 cm<sup>3</sup> schneiden.",
"Wenn Ziwebeln genügend gekocht sind die Kartoffeln hinzufügen und Milch hinzufügen, sodass alles bedeckt ist. Ca. 10 Minuten kochen lassen.",
"Ca. 1 L Milch hinzugeben. Für den nächsten Schritt wollen wir die Maccaroni hinzufügen. Damit diese nicht zu breiig werden geben wir erst die Milch zu und lassen sie aufkochen.",
"Wenn die der Topf wieder kocht jetzt die Maccaroni hinzugeben.",
"Den Käse zerreiben oder in kleine Würfel schneiden.",
"Ein bis zwei Minuten bevor die Nudeln durchgekocht sind den Käse hinzugeben und schmelzen lassen.",
"Mit Salz und Muskat würzen.",
"Den Topf ein bisschen zu früh vom Herd nehmen und ein bisschen auskühlen lassen.",
"Mit <a href=apfelkompott>Apfelmuß oder Apfelkompott</a> servieren."
]
}
],
addendum: "<p>Man kann das Gericht noch dekanter machen indem man zu Teilen Rahm an Stelle von Milch verwendet. Zudem kann man das ganze auch noch in eine Auflaufform geben und im Ofen eine Kruste anbacken</p>",
}

View File

@ -0,0 +1,50 @@
const obj =
{
short_name: "<++>",
name : "<++>",
category: "<++>",
icon: "<++>",
datecreated: 20230619,
datemodified: 20230619,
images: [{
mediapath: "<++>.webp",
alt: "<++>",
caption: "<++>",
}],
description: "<++>",
tags: [<++>],
season: [<++>],
baking: {
temperature: "<++>",
length: "<++>",
mode: "<++>",
},
preparation: "<++>",
fermentation: {
bulk: "<++>",
final: "<++>"
},
portions: "<++>",
total_time: "<++>",
ingredients: [ {
name: "<++>",
list: [
{ name: "<++>",
unit: "<++>",
amount: <++>,
},
{
name: "<++>",
unit: "<++>",
amount: <++>,
},
]},
],
instructions: [
{name: "<++>",
steps: [
"<++>",
"<++>"
]
}
]}