Skip to content
Snippets Groups Projects
Commit a1db2953 authored by Tim-Luca Taxis's avatar Tim-Luca Taxis
Browse files

edited some stuff

parent 7875ac9a
No related branches found
No related tags found
1 merge request!4added vercel integration
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Getting Started
First, run the development server:
```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
## Learn More
To learn more about Next.js, take a look at the following resources:
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
## Deploy on Vercel
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
module.exports = {
env: {
POSTGRES_URL: process.env.POSTGRES_URL,
},
};
\ No newline at end of file
/** @type {import('next').NextConfig} */
const nextConfig = {};
export default nextConfig;
This diff is collapsed.
......@@ -9,14 +9,19 @@
"lint": "next lint"
},
"dependencies": {
"next": "14.2.3",
"@babel/core": "^7.24.7",
"@babel/preset-env": "^7.24.7",
"@babel/preset-react": "^7.24.7",
"@vercel/postgres": "^0.8.0",
"next": "^14.2.3",
"pg": "^8.12.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"swr": "^2.2.5"
},
"devDependencies": {
"eslint": "^8",
"eslint-config-next": "14.2.3",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.3",
"postcss": "^8",
"tailwindcss": "^3.4.1"
}
......
......@@ -4,7 +4,7 @@ import useSWR from 'swr';
const fetcher = url => fetch(url).then(res => res.json());
const FruitList = () => {
const { data: fruits, isLoading, error } = useSWR('/api/list-fruits', fetcher, {
const { data: fruits, isLoading, error, mutate } = useSWR('/api/list-fruits', fetcher, {
revalidateOnFocus: false,
revalidateOnReconnect: false,
});
......@@ -22,7 +22,7 @@ const FruitList = () => {
{fruits && fruits.length > 0 ? (
fruits.map((fruit, index) => (
<li key={index}>
{fruit.germanName} ({fruit.latinName}), {fruit.color}, {fruit.origin}, {fruit.calories} kcal
{fruit['Deutscher Name']} ({fruit['Lateinischer Name']}), {fruit.Farbe}, {fruit.Herkunft}, {fruit.Kalorien} kcal
</li>
))
) : (
......
import { sql } from '@vercel/postgres';
export default async function handler(request, response) {
if (request.method === 'POST') {
try {
const {DeutscherName, LateinischerName, Farbe, Herkunft, Kalorien} = JSON.parse(request.body);
if (!DeutscherName || !LateinischerName || !Farbe || !Herkunft || !Kalorien) throw new Error ('Irgendwas muss hier stehen') ;
await sql `INSERT INTO Obst (id, Deutscher Name ,Lateinischer Name, Farbe, Herkunft, Kalorien) VALUES (${id}, ${DeutscherName}, ${LateinischerName}, ${Farbe}, ${Herkunft}, ${Kalorien});`;
const Obst = await sql `SELECT * FROM Obst;`;
return response.status(200).json(Obst.rows);
} catch (error) {
return response.status(500).json({ error });
const { germanName, latinName, color, origin, calories } = request.body;
if (!germanName || !latinName || !color || !origin || !calories) {
throw new Error('All fields are required');
}
await sql`
INSERT INTO obst ("Deutscher Name", "Lateinischer Name", Farbe, Herkunft, Kalorien)
VALUES (${germanName}, ${latinName}, ${color}, ${origin}, ${calories});
`;
const fruits = await sql`SELECT * FROM obst;`;
return response.status(200).json(fruits);
} catch (error) {
console.error('Error during request processing:', error);
return response.status(500).json({ error: error.message });
}
}
\ No newline at end of file
} else {
return response.status(405).json({ message: 'Method Not Allowed' });
}
}
import {sql} from '@vercel/postgres';
import { sql } from '@vercel/postgres';
export default async function handler(request, response) {
try {
const result =
await sql `CREATE TABLE Obst (
Deutscher Name varchar(50) NOT NULL,
Lateinischer Name varchar(50) NOT NULL,
const result = await sql`
CREATE TABLE IF NOT EXISTS obst (
"Deutscher Name" varchar(50) NOT NULL,
"Lateinischer Name" varchar(50) NOT NULL,
Farbe varchar(50) NOT NULL,
Herkunft varchar(200) NOT NULL,
Kalorien auf 100 Gramm int(11) NOT NULL
);`;
return response.status(200).json({ result });
} catch (errror) {
return response.status(500).json({ error });
}
}
\ No newline at end of file
Kalorien int NOT NULL
);`;
return response.status(200).json({ result });
} catch (error) {
console.error('Error creating table:', error);
return response.status(500).json({ error: error.message });
}
}
import { sql } from '@vercel/postgres'
import { sql } from '@vercel/postgres';
export default async function handler(request, response) {
if (request.method === 'GET') {
try {
const fruits = await sql `SELECT * FROM Obst;`;
return response.status(200).json(fruits.rows);
const fruits = await sql`SELECT * FROM obst;`;
return response.status(200).json(fruits);
} catch (error) {
return response.status(500).json({ error })
console.error('Error during request processing:', error);
return response.status(500).json({ error: error.message });
}
}
\ No newline at end of file
} else {
return response.status(405).json({ message: 'Method Not Allowed' });
}
}
......@@ -3,13 +3,12 @@ import Navbar from '../components/Navbar';
const Home = () => {
return (
<div>
<Navbar />
<h1>Add a New Fruit</h1>
<AddFruit />
</div>
<div>
<Navbar />
<h1>Add a New Fruit</h1>
<AddFruit onFruitAdded={() => mutate('/api/list-fruits')} />
</div>
);
};
export default Home;
\ No newline at end of file
};
export default Home;
{
"name": "dmwt_season10_group_2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"@vercel/postgres": "^0.8.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"swr": "^2.2.5"
}
},
"node_modules/@neondatabase/serverless": {
"version": "0.7.2",
"resolved": "https://registry.npmjs.org/@neondatabase/serverless/-/serverless-0.7.2.tgz",
"integrity": "sha512-wU3WA2uTyNO7wjPs3Mg0G01jztAxUxzd9/mskMmtPwPTjf7JKWi9AW5/puOGXLxmZ9PVgRFeBVRVYq5nBPhsCg==",
"dependencies": {
"@types/pg": "8.6.6"
}
},
"node_modules/@types/node": {
"version": "20.14.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.2.tgz",
"integrity": "sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==",
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/@types/pg": {
"version": "8.6.6",
"resolved": "https://registry.npmjs.org/@types/pg/-/pg-8.6.6.tgz",
"integrity": "sha512-O2xNmXebtwVekJDD+02udOncjVcMZQuTEQEMpKJ0ZRf5E7/9JJX3izhKUcUifBkyKpljyUM6BTgy2trmviKlpw==",
"dependencies": {
"@types/node": "*",
"pg-protocol": "*",
"pg-types": "^2.2.0"
}
},
"node_modules/@vercel/postgres": {
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/@vercel/postgres/-/postgres-0.8.0.tgz",
"integrity": "sha512-/QUV9ExwaNdKooRjOQqvrKNVnRvsaXeukPNI5DB1ovUTesglfR/fparw7ngo1KUWWKIVpEj2TRrA+ObRHRdaLg==",
"dependencies": {
"@neondatabase/serverless": "0.7.2",
"bufferutil": "4.0.8",
"utf-8-validate": "6.0.3",
"ws": "8.14.2"
},
"engines": {
"node": ">=14.6"
}
},
"node_modules/bufferutil": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.8.tgz",
"integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==",
"hasInstallScript": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"engines": {
"node": ">=6.14.2"
}
},
"node_modules/client-only": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz",
"integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA=="
},
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"node_modules/loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
"dependencies": {
"js-tokens": "^3.0.0 || ^4.0.0"
},
"bin": {
"loose-envify": "cli.js"
}
},
"node_modules/node-gyp-build": {
"version": "4.8.1",
"resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz",
"integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==",
"bin": {
"node-gyp-build": "bin.js",
"node-gyp-build-optional": "optional.js",
"node-gyp-build-test": "build-test.js"
}
},
"node_modules/pg-int8": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==",
"engines": {
"node": ">=4.0.0"
}
},
"node_modules/pg-protocol": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.6.1.tgz",
"integrity": "sha512-jPIlvgoD63hrEuihvIg+tJhoGjUsLPn6poJY9N5CnlPd91c2T18T/9zBtLxZSb1EhYxBRoZJtzScCaWlYLtktg=="
},
"node_modules/pg-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz",
"integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==",
"dependencies": {
"pg-int8": "1.0.1",
"postgres-array": "~2.0.0",
"postgres-bytea": "~1.0.0",
"postgres-date": "~1.0.4",
"postgres-interval": "^1.1.0"
},
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-array": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz",
"integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==",
"engines": {
"node": ">=4"
}
},
"node_modules/postgres-bytea": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz",
"integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-date": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz",
"integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/postgres-interval": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz",
"integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==",
"dependencies": {
"xtend": "^4.0.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/react": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
"dependencies": {
"loose-envify": "^1.1.0"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/react-dom": {
"version": "18.3.1",
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
"dependencies": {
"loose-envify": "^1.1.0",
"scheduler": "^0.23.2"
},
"peerDependencies": {
"react": "^18.3.1"
}
},
"node_modules/scheduler": {
"version": "0.23.2",
"resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz",
"integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==",
"dependencies": {
"loose-envify": "^1.1.0"
}
},
"node_modules/swr": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz",
"integrity": "sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==",
"dependencies": {
"client-only": "^0.0.1",
"use-sync-external-store": "^1.2.0"
},
"peerDependencies": {
"react": "^16.11.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="
},
"node_modules/use-sync-external-store": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz",
"integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==",
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
}
},
"node_modules/utf-8-validate": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-6.0.3.tgz",
"integrity": "sha512-uIuGf9TWQ/y+0Lp+KGZCMuJWc3N9BHA+l/UmHd/oUHwJJDeysyTRxNQVkbzsIWfGFbRe3OcgML/i0mvVRPOyDA==",
"hasInstallScript": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"engines": {
"node": ">=6.14.2"
}
},
"node_modules/ws": {
"version": "8.14.2",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.14.2.tgz",
"integrity": "sha512-wEBG1ftX4jcglPxgFCMJmZ2PLtSbJ2Peg6TmpJFTbe9GZYOQCDPdMYu/Tm0/bGZkw8paZnJY45J4K2PZrLYq8g==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",
"integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==",
"engines": {
"node": ">=0.4"
}
}
}
}
{
"dependencies": {
"@vercel/postgres": "^0.8.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"swr": "^2.2.5"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment