From 1539a030846f517e77b57d9efe62724ec714ff17 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Fri, 28 Jun 2024 18:35:03 +0200 Subject: [PATCH] make api call on the server add tests --- TODO.md | 6 +-- bun.lockb | Bin 418114 -> 418066 bytes composables/useRecipe.ts | 61 ------------------------ nuxt.config.ts | 1 - pages/index.vue | 4 +- pages/random.vue | 6 ++- server/api/recipes.get.ts | 12 +++++ types/recipe.ts | 2 +- utils/recipes.test.ts | 95 ++++++++++++++++++++++++++++++++++++++ utils/recipes.ts | 33 +++++++++++++ 10 files changed, 151 insertions(+), 69 deletions(-) delete mode 100644 composables/useRecipe.ts create mode 100644 server/api/recipes.get.ts create mode 100644 utils/recipes.test.ts create mode 100644 utils/recipes.ts diff --git a/TODO.md b/TODO.md index 5bbe111..de9f0fc 100644 --- a/TODO.md +++ b/TODO.md @@ -4,10 +4,10 @@ - [x] use nuxt framework - [x] rewrite the random page, the current landing page - [x] rewrite the recipe page -- [ ] deploy -- [ ] nuxt image +- [x] deploy +- [x] nuxt image - [x] prettier and eslint - [ ] transition - [ ] pwa - [ ] seo, robots.txt -- [ ] update the README +- [x] update the README diff --git a/bun.lockb b/bun.lockb index 98904ee3b98dc6045210651324e64f3c106a6040..819d8b9f569bbffe0ab0587875318f6c672fe032 100755 GIT binary patch delta 2548 zcmYk6X>6566o$Xc{kl<#0kn$(Wf9q1ij-PPfhq;D!cBn+3MFlUAI8L3qee}zmQog_ zbOQ#ZvM&V^0R^vOLgi{g1E?UNXhdmZqER3={(-vSb8cS~PjWKvJnxy)`DW%e5=m={ zq&3V5tgH^zh61&r9>+t$v9|&v+=^SlqTHIG=LI~^izO}ooA*Fh#7B|0N;M4LaG>Y{`PmdDMYZAMQ`C+kU*J&*_%ChBawZTndePQdwHpA>}`jK^FTUQaxp3)bQTEIa9uqqH z^qD(lEl$hI2EC{9c9?zKMDm!}8P(;$w!!S#oppWwro}l~xu7Sp?1_CYHVIt}vnTe2 zSRQ%_?;@4)OIL0!&STk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zvt0Bn<|2!DE)=Q72c-0iL-E#V*@rG4hCbsl`p9fJY^pY3=R>txeC$*n=%T)O?1I@y zbZ@gy%|Ip%7r$&<+;?!p_{m?yl85gLDyyUtu=ptY07ok8czI19VDIHe! zmDxD7eqDCiY&`k~qt%7@b*NN}E2LC40WZR3-@1GvdQLrwqVHfjSw243?E7$)7I{Co zya0UKgZrb|WY~GLpUm!u#rz;Y!;%xDZ^U}Uic?_9btP)c0=%(VH?tRDX=qt@BHN>4 zJl%CYi8^Kpp2LhzA@+i)Un$uo=VwFdb$IUgNz3UAGig#GK6}-c`?djAbl-1v1jp7Fw)U_e5;b!81H=%-4v}Wyw_|4I>W4Ztl>uB2=1hWIL<7f2f%cPzToo@qA4bvt3Te$|C$m9Xc`9x&Sldp=oXj7>G%jn?Gq8Xh#;gI zklD+u3w@aBFdc9ou31u#nXaos&!A5AvvmJD*nSll&h_R4u*YHAFwdJ0qV>nB`bW$T zp=ZOCd(`YOT9dBaV`e4#*0HWx4KaPl{Qe=H6>p!ImJUY9<}Eu-8}*E-%M(J3o_q;pzdeI{5{xHLHa tda7QCEU_gwe)*fUYwa3tjO)wvy&6m*(pVN{{k { - const config = useRuntimeConfig(); - - let url = ""; - - switch (keyword) { - case "random": - url = `${config.apiUrl}random.php`; - break; - case "filter": - url = ""; - break; - case "lookup": - url = `${config.apiUrl}${keyword}.php?i=${param}`; - break; - case "search": - url = ""; - break; - default: - throw Error("unexpected URI parameters"); - } - return await $fetch(url); - }, - { lazy: true }, - ); - - const tmp = computed(() => data.value?.meals?.[0]); - - const names: string[] = []; - const quantities: number[] = []; - for (const [k, v] of Object.entries(tmp.value)) { - if (k.startsWith("strIngredient") && !!v) { - names.push(v); - } else if (k.startsWith("strMeasure") && !!v) { - quantities.push(v); - } - } - - const recipe = reactive({ - title: tmp.value.strMeal, - pictureUrl: tmp.value.strMealThumb, - videoUrl: tmp.value.strYoutube, - category: tmp.value.strCategory, - origin: tmp.value.strArea, - ingredients: names.map((name, i) => ({ name, quantity: quantities[i] })), - instructions: tmp.value.strInstructions, - }); - - return { - recipe, - pending, - error, - }; -} diff --git a/nuxt.config.ts b/nuxt.config.ts index 8defe9f..c81ba69 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -16,7 +16,6 @@ export default defineNuxtConfig({ // The private keys which are only available server-side apiUrl: "", // Keys within public are also exposed client-side - public: {}, }, ssr: true, }); diff --git a/pages/index.vue b/pages/index.vue index e4df656..71e2c75 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1,11 +1,11 @@