diff --git a/.env b/.env new file mode 100644 index 0000000000000000000000000000000000000000..19eec9331621afc023e78587b6947286734c872f --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +# Environment variables declared in this file are automatically made available to Prisma. +# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema + +# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. +# See the documentation for all the connection string options: https://pris.ly/d/connection-strings + +DATABASE_URL="postgresql://djs21:3;iR5,q772@db.doc.ic.ac.uk:5432/djs21?schema=public" +SHADOW_DATABASE_URL="postgresql://rgw20:e8:4CBnj+>cn@db.doc.ic.ac.uk:5432/rgw20?schema=public" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index fcef9b92f2063d052d95cbeb754a2ff6c65beca1..478fa1015f2326b45b74ee2be999e5ceee9d83a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,8 @@ "name": "drp45", "version": "0.1.0", "dependencies": { + "@prisma/client": "^4.15.0", + "@prisma/client": "^4.15.0", "bootstrap": "^5.3.0", "eslint": "8.41.0", "eslint-config-next": "13.4.4", @@ -17,6 +19,8 @@ "react-dom": "^18.2.0" }, "devDependencies": { + "prisma": "^4.15.0", + "prisma": "^4.15.0", "cypress": "^12.13.0", "start-server-and-test": "^2.0.0" } @@ -395,6 +399,38 @@ "url": "https://opencollective.com/popperjs" } }, + "node_modules/@prisma/client": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-4.15.0.tgz", + "integrity": "sha512-xnROvyABcGiwqRNdrObHVZkD9EjkJYHOmVdlKy1yGgI+XOzvMzJ4tRg3dz1pUlsyhKxXGCnjIQjWW+2ur+YXuw==", + "hasInstallScript": true, + "dependencies": { + "@prisma/engines-version": "4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944" + }, + "engines": { + "node": ">=14.17" + }, + "peerDependencies": { + "prisma": "*" + }, + "peerDependenciesMeta": { + "prisma": { + "optional": true + } + } + }, + "node_modules/@prisma/engines": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-4.15.0.tgz", + "integrity": "sha512-FTaOCGs0LL0OW68juZlGxFtYviZa4xdQj/rQEdat2txw0s3Vu/saAPKjNVXfIgUsGXmQ72HPgNr6935/P8FNAA==", + "devOptional": true, + "hasInstallScript": true + }, + "node_modules/@prisma/engines-version": { + "version": "4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-4.15.0-28.8fbc245156db7124f997f4cecdd8d1219e360944.tgz", + "integrity": "sha512-sVOig4tjGxxlYaFcXgE71f/rtFhzyYrfyfNFUsxCIEJyVKU9rdOWIlIwQ2NQ7PntvGnn+x0XuFo4OC1jvPJKzg==" + }, "node_modules/@react-aria/ssr": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/@react-aria/ssr/-/ssr-3.6.0.tgz", @@ -4285,6 +4321,23 @@ "node": ">= 0.8.0" } }, + "node_modules/prisma": { + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/prisma/-/prisma-4.15.0.tgz", + "integrity": "sha512-iKZZpobPl48gTcSZVawLMQ3lEy6BnXwtoMj7hluoGFYu2kQ6F9LBuBrUyF95zRVnNo8/3KzLXJXJ5TEnLSJFiA==", + "devOptional": true, + "hasInstallScript": true, + "dependencies": { + "@prisma/engines": "4.15.0" + }, + "bin": { + "prisma": "build/index.js", + "prisma2": "build/index.js" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/pretty-bytes": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/pretty-bytes/-/pretty-bytes-5.6.0.tgz", diff --git a/package.json b/package.json index c97d8031b1e844c36e13d0f25fedf683bf1c9085..8788c6534d6c533979370ba1f512c7cbc077898b 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test-e2e": "start-server-and-test dev http://localhost:3000 \"cypress run --e2e\"" }, "dependencies": { + "@prisma/client": "^4.15.0", "bootstrap": "^5.3.0", "eslint": "8.41.0", "eslint-config-next": "13.4.4", @@ -21,6 +22,7 @@ "react-dom": "^18.2.0" }, "devDependencies": { + "prisma": "^4.15.0", "cypress": "^12.13.0", "start-server-and-test": "^2.0.0" } diff --git a/prisma/migrations/20230601114814_init/migration.sql b/prisma/migrations/20230601114814_init/migration.sql new file mode 100644 index 0000000000000000000000000000000000000000..b2ec550c31d4a1b5ff2d24b41101ed3d4152ea1f --- /dev/null +++ b/prisma/migrations/20230601114814_init/migration.sql @@ -0,0 +1,8 @@ +-- CreateTable +CREATE TABLE "Student" ( + "id" SERIAL NOT NULL, + "language" TEXT NOT NULL, + "maths" TEXT NOT NULL, + + CONSTRAINT "Student_pkey" PRIMARY KEY ("id") +); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000000000000000000000000000000000000..fbffa92c2bb7c748d6fc78f9f9dcac604dabb87d --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000000000000000000000000000000000000..5a68d4cde4162d9cd3b5257c375ad57e833b8a90 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,18 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") + shadowDatabaseUrl = env("SHADOW_DATABASE_URL") +} + +model Student { + id Int @id @default(autoincrement()) + language String + maths String +} \ No newline at end of file diff --git a/src/app/api/student/route.js b/src/app/api/student/route.js new file mode 100644 index 0000000000000000000000000000000000000000..8757b54714ca4ca51cad7e88db954eb4e5fcb455 --- /dev/null +++ b/src/app/api/student/route.js @@ -0,0 +1,23 @@ +import { PrismaClient } from '@prisma/client'; +import { NextResponse } from 'next/server'; + +const prisma = new PrismaClient(); + +export async function GET() { + const student = await prisma.student.findFirst(); + return NextResponse.json(student); +} + +export async function PUT(request) { + const { language, maths } = await request.json(); + await prisma.student.update({ + where: { + id: 1 + }, + data: { + language: language, + maths: maths + } + }); + return NextResponse.json({}); +} \ No newline at end of file diff --git a/src/app/studentDashboard/page.js b/src/app/studentDashboard/page.js index 9a647f46015ce6e6ae7d6c38ae19e4f8744e86e2..2dbe77c7b6b2bf50686f9e25209f3ee0d4a32569 100644 --- a/src/app/studentDashboard/page.js +++ b/src/app/studentDashboard/page.js @@ -1,56 +1,75 @@ 'use client' - import "bootstrap/dist/css/bootstrap.min.css" import Accordion from 'react-bootstrap/Accordion'; import Form from 'react-bootstrap/Form'; import Nav from 'react-bootstrap/Nav'; import Button from 'react-bootstrap/Button'; +import { useEffect, useState, useRef } from 'react'; + +function StudentDashboard() { + const langRef = useRef(); + const mathRef = useRef(); + + const handleSubmit = (event) => { + event.preventDefault(); + fetch('/api/student', { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + language : langRef.current.value, + maths : mathRef.current.value + }), + }); + } + + const [student, setStudent] = useState([]); + useEffect(() => { + fetch('/api/student') + .then((response) => response.json()) + .then((data) => {setStudent(data)} ); + }, []); -function studentDashboard() { return ( <main className="studentDashboard"> <Nav fill className="justify-content-center" activeKey="/home"> - <Nav.Item> - <h6>3 Requirements Matched </h6> - </Nav.Item> - <Nav.Item> - <h4>Your Application </h4> - </Nav.Item> - <Nav.Item> - <Nav.Link eventKey="link-2">Upload CV</Nav.Link> - </Nav.Item> + <Nav.Item> + <h6>3 Requirements Matched </h6> + </Nav.Item> + <Nav.Item> + <h4>Your Application </h4> + </Nav.Item> + <Nav.Item> + <Nav.Link eventKey="link-2">Upload CV</Nav.Link> + </Nav.Item> </Nav> - - <Form> - <Accordion defaultActiveKey={['0']} alwaysOpen> - <Accordion.Item eventKey="0"> - <Accordion.Header>Language Skill</Accordion.Header> - <Accordion.Body> - <Form.Group className="mb-3" controlId="formGroupSkill1"> - <Form.Control as="textarea" rows={3} placeholder="Enter your evidence of the skill"/> - </Form.Group> - </Accordion.Body> - </Accordion.Item> - <Accordion.Item eventKey="1"> - <Accordion.Header>Profient in Maths</Accordion.Header> - <Accordion.Body> - <Form.Group className="mb-3" controlId="formGroupSkill2"> - <Form.Label>Password</Form.Label> - <Form.Control as="textarea" rows={3} placeholder="Enter your evidence of the skill"/> - </Form.Group> - </Accordion.Body> - </Accordion.Item> + <Form onSubmit={handleSubmit}> + <Accordion defaultActiveKey={['0']} alwaysOpen> + <Accordion.Item eventKey="0"> + <Accordion.Header>Language Skill</Accordion.Header> + <Accordion.Body> + <Form.Group className="mb-3" controlId="formGroupSkill1"> + <Form.Control as="textarea" rows={3} placeholder="Enter your evidence of the skill" defaultValue={student.language} ref={langRef}/> + </Form.Group> + </Accordion.Body> + </Accordion.Item> + <Accordion.Item eventKey="1"> + <Accordion.Header>Profient in Maths</Accordion.Header> + <Accordion.Body> + <Form.Group className="mb-3" controlId="formGroupSkill2"> + <Form.Control as="textarea" rows={3} placeholder="Enter your evidence of the skill" defaultValue={student.maths} ref={mathRef}/> + </Form.Group> + </Accordion.Body> + </Accordion.Item> </Accordion> + <Button variant="primary" type="submit"> + Submit + </Button> </Form> - - <Button variant="primary" type="submit"> - Submit - </Button> </main> - - ); } -export default studentDashboard; +export default StudentDashboard;