From 6818e969606f967e86120b96cdd38e927534e9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Domonkos?= <144695310+IvnDmnks@users.noreply.github.com> Date: Fri, 11 Oct 2024 22:12:54 +0200 Subject: [PATCH] Feat/newproject (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * added basic authsch login * new project page added --------- Co-authored-by: Bujdosó Gergő --- .env | 2 +- .../migrations/20241011172547_/migration.sql | 50 ++++ apps/frontend/.env | 1 + apps/frontend/package.json | 1 + apps/frontend/src/app/newproject/page.tsx | 9 + apps/frontend/src/components/NewProject.tsx | 84 +++++++ .../src/components/SprintRegistration.tsx | 7 +- apps/frontend/src/lib/axiosConfig.ts | 6 + package-lock.json | 234 +++++++++++++++++- package.json | 1 + yarn.lock | 15 ++ 11 files changed, 398 insertions(+), 12 deletions(-) create mode 100644 apps/backend/prisma/migrations/20241011172547_/migration.sql create mode 100644 apps/frontend/.env create mode 100644 apps/frontend/src/app/newproject/page.tsx create mode 100644 apps/frontend/src/components/NewProject.tsx create mode 100644 apps/frontend/src/lib/axiosConfig.ts diff --git a/.env b/.env index 153f9d9..1888837 100644 --- a/.env +++ b/.env @@ -4,4 +4,4 @@ # 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://johndoe:randompassword@localhost:5432/mydb?schema=public" \ No newline at end of file +DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public" diff --git a/apps/backend/prisma/migrations/20241011172547_/migration.sql b/apps/backend/prisma/migrations/20241011172547_/migration.sql new file mode 100644 index 0000000..63f6850 --- /dev/null +++ b/apps/backend/prisma/migrations/20241011172547_/migration.sql @@ -0,0 +1,50 @@ +-- CreateEnum +CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER'); + +-- AlterTable +ALTER TABLE "User" ADD COLUMN "role" "Role" NOT NULL DEFAULT 'USER'; + +-- CreateTable +CREATE TABLE "Projekt" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "description" TEXT NOT NULL, + "userId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Projekt_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Sprint" ( + "id" SERIAL NOT NULL, + "name" TEXT NOT NULL, + "startDate" TIMESTAMP(3) NOT NULL, + "endDate" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Sprint_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Tasks" ( + "id" SERIAL NOT NULL, + "description" TEXT NOT NULL, + "sprintId" INTEGER NOT NULL, + "userId" INTEGER NOT NULL, + "projektId" INTEGER NOT NULL, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Tasks_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "Projekt" ADD CONSTRAINT "Projekt_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_sprintId_fkey" FOREIGN KEY ("sprintId") REFERENCES "Sprint"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_projektId_fkey" FOREIGN KEY ("projektId") REFERENCES "Projekt"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/apps/frontend/.env b/apps/frontend/.env new file mode 100644 index 0000000..9bdee49 --- /dev/null +++ b/apps/frontend/.env @@ -0,0 +1 @@ +BACKEND_URL= https://localhost:3001 diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 25f11bf..9802f26 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -12,6 +12,7 @@ "lint": "next lint" }, "dependencies": { + "axios": "^1.7.7", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "frontend": "file:", diff --git a/apps/frontend/src/app/newproject/page.tsx b/apps/frontend/src/app/newproject/page.tsx new file mode 100644 index 0000000..521ddcc --- /dev/null +++ b/apps/frontend/src/app/newproject/page.tsx @@ -0,0 +1,9 @@ +import SprintLogin from '../../components/NewProject'; + +export default function Home() { + return ( +
+ +
+ ); +} diff --git a/apps/frontend/src/components/NewProject.tsx b/apps/frontend/src/components/NewProject.tsx new file mode 100644 index 0000000..78970a1 --- /dev/null +++ b/apps/frontend/src/components/NewProject.tsx @@ -0,0 +1,84 @@ +'use client'; +import { FormEvent, useState } from 'react'; + +import api from '../lib/axiosConfig'; +import { Footer } from './Footer'; +import Navbar from './Navbar'; + +export default function NewProject() { + const [formData, setFormData] = useState({ + name: '', + description: '', + }); + + const [errorMessage, setErrorMessage] = useState(null); + + const handleChange = (event: { target: { name: any; value: any } }) => { + setFormData({ ...formData, [event.target.name]: event.target.value }); + console.log('asda'); + }; + + const projectFormState = async (event: FormEvent) => { + event.preventDefault(); + console.log(formData); + if (!formData.name || !formData.description) { + setErrorMessage('Incomplete Row(s)'); + return; + } + + try { + await api('/project', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + data: JSON.stringify(formData), + }); + } catch (error) { + console.log((error as any).message); + } + }; + + return ( +
+ +
+

+ Új Projekt Létrehozása +

+ {errorMessage &&

{errorMessage}

} +
+
+ + +
+
+ +