diff --git a/gritella_matteo/TPSI/SvelteForm/src/routes/+page.server.js b/gritella_matteo/TPSI/SvelteForm/src/routes/+page.server.js index 8b44bdb..dc1c3f0 100644 --- a/gritella_matteo/TPSI/SvelteForm/src/routes/+page.server.js +++ b/gritella_matteo/TPSI/SvelteForm/src/routes/+page.server.js @@ -1,26 +1,43 @@ - let utenti = [ - {nome: "Matteo",cognome: "Gritella",eta: "18"}, - {nome: "Alex",cognome: "Pava",eta: "18"}, - {nome: "Vasile",cognome: "Timis",eta: "18"}, - {nome: "Matteo",cognome: "Rossi",eta: "17"}, - ]; - export function load({params}){ - console.log("ESECUZIONE FUNZIONE LOAD", Date.now()); - - return { - utenti - } } - - export const actions ={ - default: async({cookies,request}) => { - const data= await request.formData(); - console.log("I valori del FORM sono:",data); - - utenti.push({ - nome: data.get("nome"), +export const csr = true; // csr attivo +export const ssr = true; //ssr attivo + +let utenti = [ + {nome: "Mario", cognome: "Rossi",eta:25}, + {nome: "Luca", cognome: "Bianchi",eta:15}, + {nome: "Gianni", cognome: "Verdi", eta:19}, + {nome: "Pino", cognome: "RossSilvedtrei",eta:27}, + +]; + +export function load({params}) { + console.log("ESECUZIONE FUNZIONE LOAD:", Date.now()); + + return { + utenti + } +} + + +export const actions = { + default: async ({cookies,request}) => { + const data = await request.formData(); + console.log("I VALORI DEL FORM SONO:", data ); + + const user = { + nome:data.get("nome"), cognome: data.get("cognome"), eta: data.get("eta") - }) - } - }; - + } + if (user.nome && user.cognome && user.eta) { + + utenti.push(user); + } + else { + return{ + form_error: true, + form_vals: user + + } + } +}, +}; diff --git a/gritella_matteo/TPSI/SvelteForm/src/routes/+page.svelte b/gritella_matteo/TPSI/SvelteForm/src/routes/+page.svelte index 224e1c6..b61b1dd 100644 --- a/gritella_matteo/TPSI/SvelteForm/src/routes/+page.svelte +++ b/gritella_matteo/TPSI/SvelteForm/src/routes/+page.svelte @@ -1,36 +1,58 @@ -
Visit svelte.dev/docs/kit to read the documentation
diff --git a/gritella_matteo/TPSI/api/todo-api/src/routes/api/todo/[[id]]/+server.js b/gritella_matteo/TPSI/api/todo-api/src/routes/api/todo/[[id]]/+server.js new file mode 100644 index 0000000..db40211 --- /dev/null +++ b/gritella_matteo/TPSI/api/todo-api/src/routes/api/todo/[[id]]/+server.js @@ -0,0 +1,82 @@ +import { json } from '@sveltejs/kit'; + +let todos = [ + { + id: 1, + task: "studiare TPSI", + done: false, + priority: 3 + }, + + { + id: 2, + task: "fare wl", + done: false, + priority: 1 + } +]; + +export async function GET(params, request) { + + console.log("ricevuto HTTP GET") + + if(params.id){ + const todo=todos.filter(t=> t.id == params.id)[0]; + return json(todos); + } + else{ + return json(todos); + } + + + +} + + +export async function POST({ request }) { + console.log("Ricevuto HTTP POST"); + + const body = await request.json(); + console.log("POST BODY:", body); + + body['id'] = Math.ceil(Math.random() * 100); + + todos.push(body); + + return json('OK'); + } + + + export async function PUT({ params, request }) { + console.log("Ricevuto HTTP PUT con parametro:", params); + + const body = await request.json(); + console.log("PUT BODY:", body); + + let todo = todos.findIndex(t => t.id == params.id); + todos[todo] = body; + + return json('OK'); + } + + + export async function PATCH({ params, request }) { + console.log("Ricevuto HTTP PATCH con parametro:", params); + + let body = await request.json(); + + let todo = todos.findIndex(t => t.id == params.id); + + const key = Object.keys(body); + todos[todo][key] = body[key]; + + return json('OK'); + } + + +export async function DELETE(params,request) { + console.log("Ricevuto HTTP DELETE con parametro:",params) + todos=todos.filter(t=> t.id!=params.id); + return json('Ok'); + +} \ No newline at end of file diff --git a/gritella_matteo/TPSI/api/todo-api/static/robots.txt b/gritella_matteo/TPSI/api/todo-api/static/robots.txt new file mode 100644 index 0000000..b6dd667 --- /dev/null +++ b/gritella_matteo/TPSI/api/todo-api/static/robots.txt @@ -0,0 +1,3 @@ +# allow crawling everything by default +User-agent: * +Disallow: diff --git a/gritella_matteo/TPSI/api/todo-api/svelte.config.js b/gritella_matteo/TPSI/api/todo-api/svelte.config.js new file mode 100644 index 0000000..10c4eeb --- /dev/null +++ b/gritella_matteo/TPSI/api/todo-api/svelte.config.js @@ -0,0 +1,13 @@ +import adapter from '@sveltejs/adapter-auto'; + +/** @type {import('@sveltejs/kit').Config} */ +const config = { + kit: { + // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. + // If your environment is not supported, or you settled on a specific environment, switch out the adapter. + // See https://svelte.dev/docs/kit/adapters for more information about adapters. + adapter: adapter() + } +}; + +export default config; diff --git a/gritella_matteo/TPSI/api/todo-api/vite.config.js b/gritella_matteo/TPSI/api/todo-api/vite.config.js new file mode 100644 index 0000000..02ff9dc --- /dev/null +++ b/gritella_matteo/TPSI/api/todo-api/vite.config.js @@ -0,0 +1,9 @@ +import { sveltekit } from '@sveltejs/kit/vite'; +import { defineConfig } from 'vite'; + +export default defineConfig({ + plugins: [sveltekit()], + server:{ + host: '0.0.0.0' + } +});