first working prototype
This commit is contained in:
23
src/routes/api/add/+server.ts
Normal file
23
src/routes/api/add/+server.ts
Normal 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 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.create(recipe_json);
|
||||
await dbDisconnect();
|
||||
return {status: 400}
|
||||
}
|
||||
else{
|
||||
return {status: 403}
|
||||
}
|
||||
};
|
@ -1,13 +1,11 @@
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
import type { BriefRecipeType } from '../../../../types/types';
|
||||
import { Recipe } from '../../../../models/Recipe'
|
||||
import { dbConnect, dbDisconnect } from '../../../../utils/db';
|
||||
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
let current_month = 6;
|
||||
await dbConnect();
|
||||
let found_brief = (await Recipe.find({}, 'name short_name images tags category icon description season').lean());
|
||||
let found_brief = (await Recipe.find({}, 'name short_name images tags category icon description season').lean()) as BriefRecipeType[];
|
||||
await dbDisconnect();
|
||||
console.log(found_brief)
|
||||
let recipes = JSON.parse(JSON.stringify(found_brief));
|
||||
return json(recipes);
|
||||
return json(JSON.parse(JSON.stringify(found_brief)));
|
||||
};
|
||||
|
13
src/routes/api/items/category/+server.ts
Normal file
13
src/routes/api/items/category/+server.ts
Normal 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 categories = (await Recipe.distinct('category').lean());
|
||||
await dbDisconnect();
|
||||
|
||||
categories= JSON.parse(JSON.stringify(categories));
|
||||
return json(categories);
|
||||
};
|
13
src/routes/api/items/category/[category]/+server.ts
Normal file
13
src/routes/api/items/category/[category]/+server.ts
Normal 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({category: params.category}, 'name short_name images tags category icon description season').lean()) as BriefRecipeType[];
|
||||
await dbDisconnect();
|
||||
|
||||
recipes = JSON.parse(JSON.stringify(recipes));
|
||||
return json(recipes);
|
||||
};
|
@ -1,12 +0,0 @@
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
import { Recipe } from '../../../../models/Recipe'
|
||||
import { dbConnect, dbDisconnect } from '../../../../utils/db';
|
||||
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
let current_month = 6;
|
||||
await dbConnect();
|
||||
let found_in_season = (await Recipe.find({season: current_month}, 'name short_name images tags category icon description season').lean());
|
||||
await dbDisconnect();
|
||||
found_in_season = JSON.parse(JSON.stringify(found_in_season));
|
||||
return json(found_in_season);
|
||||
};
|
11
src/routes/api/items/in_season/[month]/+server.ts
Normal file
11
src/routes/api/items/in_season/[month]/+server.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { json, type RequestHandler } from '@sveltejs/kit';
|
||||
import { Recipe } from '../../../../../models/Recipe'
|
||||
import { dbConnect, dbDisconnect } from '../../../../../utils/db';
|
||||
|
||||
export const GET: RequestHandler = async ({params}) => {
|
||||
await dbConnect();
|
||||
let found_in_season = (await Recipe.find({season: params.month}, 'name short_name images tags category icon description season').lean());
|
||||
await dbDisconnect();
|
||||
found_in_season = JSON.parse(JSON.stringify(found_in_season));
|
||||
return json(found_in_season);
|
||||
};
|
13
src/routes/api/items/tag/+server.ts
Normal file
13
src/routes/api/items/tag/+server.ts
Normal 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 categories = (await Recipe.distinct('tags').lean());
|
||||
await dbDisconnect();
|
||||
|
||||
categories= JSON.parse(JSON.stringify(categories));
|
||||
return json(categories);
|
||||
};
|
@ -2,22 +2,177 @@ import { json } from '@sveltejs/kit';
|
||||
import { Recipe } from '../../../models/Recipe';
|
||||
import { dbConnect, dbDisconnect } from '../../../utils/db';
|
||||
|
||||
const test_json = [
|
||||
const test_json = [{
|
||||
short_name: "anisbroetli",
|
||||
name : "Anisbrötli",
|
||||
category: "Guetzli",
|
||||
icon: "🎄",
|
||||
datecreated: 20230619,
|
||||
datemodified: 20230619,
|
||||
images: [{
|
||||
mediapath: "anisbrot.webp",
|
||||
alt: "Ein ganzes Brot",
|
||||
caption: "",
|
||||
}],
|
||||
description: "Einfach und sehr lecker",
|
||||
tags: ["backen", "advent", "schweiz", "deutschland", "anis", "weihnachtenn", "kekse"],
|
||||
season: [ 12,1],
|
||||
baking: {
|
||||
temperature: "220",
|
||||
length: "40 Minuten",
|
||||
mode: "Ober-/Unterhitze",
|
||||
},
|
||||
preparation: "20 Minuten",
|
||||
fermentation: {
|
||||
bulk: "2.5 Stunden",
|
||||
final: "2 Stunden"
|
||||
},
|
||||
portions: "4 Pizzen",
|
||||
total_time: "1 Tag",
|
||||
ingredients: [],
|
||||
instructions: []
|
||||
},
|
||||
{
|
||||
short_name: "alragu",
|
||||
name : "Pasta al Ragù",
|
||||
category: "Pasta",
|
||||
icon: "☀️",
|
||||
datecreated: 20230619,
|
||||
datemodified: 20230619,
|
||||
images: [{
|
||||
mediapath: "al_ragu.webp",
|
||||
alt: "Ein ganzes Brot",
|
||||
caption: "",
|
||||
}],
|
||||
description: "Einfach und sehr lecker",
|
||||
tags: ["pasta", "fleisch", "rind", "italienisch", "bolognese"],
|
||||
season: [ 6,7,8,9],
|
||||
baking: {
|
||||
temperature: "220",
|
||||
length: "40 Minuten",
|
||||
mode: "Ober-/Unterhitze",
|
||||
},
|
||||
preparation: "20 Minuten",
|
||||
fermentation: {
|
||||
bulk: "2.5 Stunden",
|
||||
final: "2 Stunden"
|
||||
},
|
||||
portions: "4 Pizzen",
|
||||
total_time: "1 Tag",
|
||||
ingredients: [ {
|
||||
name: "Teig",
|
||||
list: [
|
||||
{name: "Mehl",
|
||||
unit: "g",
|
||||
amount: 500
|
||||
} ,
|
||||
{
|
||||
name: "Salz",
|
||||
unit: "g",
|
||||
amount: 6
|
||||
}
|
||||
]},
|
||||
{
|
||||
name: "Füllung",
|
||||
list: [
|
||||
{
|
||||
name: "Aprikose",
|
||||
unit: "Stück",
|
||||
amount: 10
|
||||
},
|
||||
{
|
||||
name: "Zuckerwürfel",
|
||||
unit: "Stück",
|
||||
amount: 10
|
||||
}
|
||||
] }
|
||||
],
|
||||
instructions: [
|
||||
{name: "",
|
||||
steps: [
|
||||
"Den Rhabarber schälen und in ca. 1 cm große Stücke schneiden",
|
||||
"Have fun"
|
||||
]
|
||||
}
|
||||
]},
|
||||
{
|
||||
short_name: "sauerteigbrot",
|
||||
name : "Simples Sauerteigbrot",
|
||||
category: "Brot",
|
||||
icon: "🍂",
|
||||
datecreated: 20230619,
|
||||
datemodified: 20230619,
|
||||
images: [{
|
||||
mediapath: "sauerteigbrot.webp",
|
||||
alt: "Ein ganzes Brot",
|
||||
caption: "",
|
||||
}],
|
||||
description: "Einfach und sehr lecker",
|
||||
tags: ["brot", "backen", "sauerteig", "hefe"],
|
||||
season: [],
|
||||
baking: {
|
||||
temperature: "220",
|
||||
length: "40 Minuten",
|
||||
mode: "Ober-/Unterhitze",
|
||||
},
|
||||
preparation: "20 Minuten",
|
||||
fermentation: {
|
||||
bulk: "2.5 Stunden",
|
||||
final: "2 Stunden"
|
||||
},
|
||||
portions: "4 Pizzen",
|
||||
total_time: "1 Tag",
|
||||
ingredients: [ {
|
||||
name: "Teig",
|
||||
list: [
|
||||
{name: "Mehl",
|
||||
unit: "g",
|
||||
amount: 500
|
||||
} ,
|
||||
{
|
||||
name: "Salz",
|
||||
unit: "g",
|
||||
amount: 6
|
||||
}
|
||||
]},
|
||||
{
|
||||
name: "Füllung",
|
||||
list: [
|
||||
{
|
||||
name: "Aprikose",
|
||||
unit: "Stück",
|
||||
amount: 10
|
||||
},
|
||||
{
|
||||
name: "Zuckerwürfel",
|
||||
unit: "Stück",
|
||||
amount: 10
|
||||
}
|
||||
] }
|
||||
],
|
||||
instructions: [
|
||||
{name: "",
|
||||
steps: [
|
||||
"Den Rhabarber schälen und in ca. 1 cm große Stücke schneiden",
|
||||
"Have fun"
|
||||
]
|
||||
}
|
||||
]},
|
||||
{ short_name: "rhabarberkonfi",
|
||||
name: "Rharbarberkonfi",
|
||||
name: "Rhabarberkonfi",
|
||||
category: "Aufstrich",
|
||||
icon: "☀️",
|
||||
datecreated: 20230610,
|
||||
datemodified: 20230611,
|
||||
images:
|
||||
[ {
|
||||
mediapath: "rharbarberkonfi.webp",
|
||||
mediapath: "rhabarberkonfi.webp",
|
||||
alt: "Ein Brot mit Marmelade darauf.",
|
||||
caption: ""
|
||||
}
|
||||
],
|
||||
description: "Saure Marmelade",
|
||||
tags:["marmelade", "schweiz", "sauer", "rhabarber", "zucker", "aufstrich", "marmelade" , "ein weteres langes tag", "und noch eins", "und ein weiteres", "und nochmal"],
|
||||
tags:["marmelade", "sauer", "sommer", "süß"],
|
||||
season: [4,5,6],
|
||||
baking: {
|
||||
temperature: "160",
|
||||
@ -68,22 +223,22 @@ const test_json = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{ short_name: "osterfladen",
|
||||
name: "Osterfladen",
|
||||
category: "Aufstrich",
|
||||
{ short_name: "osterkuchen",
|
||||
name: "Osterkuchen",
|
||||
category: "Kuchen",
|
||||
icon: "🐇",
|
||||
datecreated: 20230610,
|
||||
datemodified: 20230611,
|
||||
images:
|
||||
[ {
|
||||
mediapath: "osterfladen.webp",
|
||||
mediapath: "osterkuchen.webp",
|
||||
alt: "Ein Brot mit Marmelade darauf.",
|
||||
caption: ""
|
||||
}
|
||||
],
|
||||
description: "Saure Marmelade",
|
||||
tags:["marmelade", "schweiz", "sauer", "rhabarber", "zucker", "aufstrich", "marmelade"],
|
||||
season: [2,3,4],
|
||||
tags:["schweiz", "ostern", "milchreis", "aprikosen", 'backen', 'süß', "marmelade"],
|
||||
season: [3,4],
|
||||
baking: {
|
||||
temperature: "160",
|
||||
length: "4 Stunden",
|
||||
|
Reference in New Issue
Block a user