From 7637930fdde6578983bc3e1d161b35003194f066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Sat, 17 Aug 2024 14:23:58 +0200 Subject: [PATCH 1/8] calendar only frontend --- apps/frontend/src/app/calendarPage/page.tsx | 84 +++++++++++++++++++ apps/frontend/src/app/layout.tsx | 2 - .../frontend/src/components/calendarStyles.ts | 68 +++++++++++++++ apps/frontend/src/components/navbar.tsx | 4 +- 4 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 apps/frontend/src/app/calendarPage/page.tsx create mode 100644 apps/frontend/src/components/calendarStyles.ts diff --git a/apps/frontend/src/app/calendarPage/page.tsx b/apps/frontend/src/app/calendarPage/page.tsx new file mode 100644 index 0000000..c365d89 --- /dev/null +++ b/apps/frontend/src/app/calendarPage/page.tsx @@ -0,0 +1,84 @@ +import { styles } from '@/components/calendarStyles'; + +// Segédfüggvények +const daysInWeek = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat', 'Vasárnap']; +const monthNames = [ + 'Január', + 'Február', + 'Március', + 'Április', + 'Május', + 'Június', + 'Július', + 'Augusztus', + 'Szeptember', + 'Október', + 'November', + 'December', +]; + +const getDaysInMonth = (month: number, year: number) => { + return new Date(year, month + 1, 0).getDate(); +}; + +const getFirstDayOfMonth = (month: number, year: number) => { + return new Date(year, month, 1).getDay(); +}; + +// Calendar komponens +const Calendar: React.FC = () => { + const currentMonth = 7; // Augusztus + const currentYear = 2024; // 2024 + + const daysInMonth = getDaysInMonth(currentMonth, currentYear); + const firstDayOfMonth = getFirstDayOfMonth(currentMonth, currentYear); + + const renderDays = () => { + const days = []; + + // Üres cellák a hónap első napja előtt + for (let i = 1; i < firstDayOfMonth; i++) { + days.push(
); + } + + // A hónap napjai + for (let i = 1; i <= daysInMonth; i++) { + days.push( +
+
{i}
+
+ ); + } + + // Üres cellák a hónap utolsó napja után + const totalDays = days.length; + const remainingDays = (7 - (totalDays % 7)) % 7; + for (let i = 0; i < remainingDays; i++) { + days.push(
); + } + + return days; + }; + + return ( +
+
+ +
{monthNames[currentMonth]}
+ +
+
+
+ {daysInWeek.map((day) => ( +
+ {day} +
+ ))} +
+
{renderDays()}
+
+
+ ); +}; + +export default Calendar; diff --git a/apps/frontend/src/app/layout.tsx b/apps/frontend/src/app/layout.tsx index 79e8dee..f9d1c85 100644 --- a/apps/frontend/src/app/layout.tsx +++ b/apps/frontend/src/app/layout.tsx @@ -3,7 +3,6 @@ import './globals.css'; import type { Metadata } from 'next'; import Navbar from '@/components/navbar'; -import NewEvent from '@/pages/newEvent'; export const metadata: Metadata = { title: 'ProgramSCH', @@ -19,7 +18,6 @@ export default function RootLayout({ - {children} diff --git a/apps/frontend/src/components/calendarStyles.ts b/apps/frontend/src/components/calendarStyles.ts new file mode 100644 index 0000000..59443da --- /dev/null +++ b/apps/frontend/src/components/calendarStyles.ts @@ -0,0 +1,68 @@ +export const styles = { + calendarContainer: { + marginTop: '1.25rem', + width: '91.666667%', + marginLeft: '4rem', + fontFamily: 'sans-serif', + }, + calendarHeader: { + display: 'flex', + alignItems: 'center', + marginBottom: '0.625rem', + borderRadius: '0.5rem', + width: '11rem', + padding: '0.25rem', + backgroundColor: '#7eb397', + borderColor: '#18633d', + borderWidth: '2px', + }, + button: { + paddingLeft: '0.5rem', + paddingRight: '0.5rem', + paddingTop: '0.25rem', + paddingBottom: '0.25rem', + fontSize: '1.125rem', + fontWeight: 'bold', + }, + monthLabel: { + fontSize: '1.25rem', + fontWeight: 'bold', + padding: '0.25rem', + backgroundColor: '#e0e0e0', + borderRadius: '0.5rem', + }, + dayName: { + backgroundColor: '#18633d', + color: '#fff', + borderRadius: '0.5rem', + height: '3rem', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + fontSize: '20px', + }, + day: { + marginTop: '0.25rem', + height: '6rem', + backgroundColor: '#7eb397', + borderColor: '#ccc', + borderWidth: '1px', + borderRadius: '0.5rem', + display: 'flex', + justifyContent: 'flex-end', + alignItems: 'flex-start', + padding: '0.5rem', + }, + emptyDay: { + marginTop: '0.25rem', + width: '100%', + height: '6rem', + backgroundColor: '#e0e0e0', + borderRadius: '0.5rem', + }, + grid: { + display: 'grid', + gridTemplateColumns: 'repeat(7, minmax(0, 1fr))', + gap: '0.25rem', + }, +}; diff --git a/apps/frontend/src/components/navbar.tsx b/apps/frontend/src/components/navbar.tsx index fe985a5..a2a329e 100644 --- a/apps/frontend/src/components/navbar.tsx +++ b/apps/frontend/src/components/navbar.tsx @@ -12,13 +12,13 @@ function Navbar() { Logo
- + ProgramSCH
- +
From e1ee948c0f769cf8198cbb3b76c88d11a0e1456a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Sat, 17 Aug 2024 22:34:51 +0200 Subject: [PATCH 2/8] changed file location --- apps/frontend/src/app/newEvent/page.tsx | 54 +++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 apps/frontend/src/app/newEvent/page.tsx diff --git a/apps/frontend/src/app/newEvent/page.tsx b/apps/frontend/src/app/newEvent/page.tsx new file mode 100644 index 0000000..e00add9 --- /dev/null +++ b/apps/frontend/src/app/newEvent/page.tsx @@ -0,0 +1,54 @@ +import Button from '@/components/button'; +import Input from '@/components/input'; +import { styles } from '@/components/newEventStyles'; + +export default function newEvent() { + return ( +
+
+
+ Event létrehozása +
+
+
+ Név: + +
+
+ Szín: +
+
+
+
+ Helyszín: + +
+
+ Tagek: + +
+
+
+
+ Időpont: + +
+
+ Szervezők: + +
+
+
+ Leírás: +
+ +
+
+
+
+
+
+ ); +} From 251e6d3461d6808b5107474f94b9e739a47b859d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Sat, 17 Aug 2024 22:36:00 +0200 Subject: [PATCH 3/8] removed the changed file --- apps/frontend/src/pages/newEvent.tsx | 54 ---------------------------- 1 file changed, 54 deletions(-) delete mode 100644 apps/frontend/src/pages/newEvent.tsx diff --git a/apps/frontend/src/pages/newEvent.tsx b/apps/frontend/src/pages/newEvent.tsx deleted file mode 100644 index e00add9..0000000 --- a/apps/frontend/src/pages/newEvent.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import Button from '@/components/button'; -import Input from '@/components/input'; -import { styles } from '@/components/newEventStyles'; - -export default function newEvent() { - return ( -
-
-
- Event létrehozása -
-
-
- Név: - -
-
- Szín: -
-
-
-
- Helyszín: - -
-
- Tagek: - -
-
-
-
- Időpont: - -
-
- Szervezők: - -
-
-
- Leírás: -
- -
-
-
-
-
-
- ); -} From f86a68fd6010751199e17086474f558c7f47a292 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Wed, 11 Sep 2024 10:20:59 +0200 Subject: [PATCH 4/8] working calendar (added useState) --- apps/frontend/src/app/calendarPage/page.tsx | 36 ++++++++++++++++--- .../frontend/src/components/calendarStyles.ts | 4 ++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/apps/frontend/src/app/calendarPage/page.tsx b/apps/frontend/src/app/calendarPage/page.tsx index c365d89..09ab92d 100644 --- a/apps/frontend/src/app/calendarPage/page.tsx +++ b/apps/frontend/src/app/calendarPage/page.tsx @@ -1,3 +1,7 @@ +'use client'; + +import React, { useState } from 'react'; + import { styles } from '@/components/calendarStyles'; // Segédfüggvények @@ -27,12 +31,32 @@ const getFirstDayOfMonth = (month: number, year: number) => { // Calendar komponens const Calendar: React.FC = () => { - const currentMonth = 7; // Augusztus - const currentYear = 2024; // 2024 + const [currentMonth, setCurrentMonth] = useState(7); // Augusztus + const [currentYear, setCurrentYear] = useState(2024); // 2024 const daysInMonth = getDaysInMonth(currentMonth, currentYear); const firstDayOfMonth = getFirstDayOfMonth(currentMonth, currentYear); + const handlePrevMonth = () => { + if (currentMonth === 0) { + // Ha január van, lépj vissza decemberre és csökkentsd az évet + setCurrentMonth(11); + setCurrentYear(currentYear - 1); + } else { + setCurrentMonth(currentMonth - 1); + } + }; + + const handleNextMonth = () => { + if (currentMonth === 11) { + // Ha december van, lépj előre januárra és növeld az évet + setCurrentMonth(0); + setCurrentYear(currentYear + 1); + } else { + setCurrentMonth(currentMonth + 1); + } + }; + const renderDays = () => { const days = []; @@ -63,9 +87,13 @@ const Calendar: React.FC = () => { return (
- +
{monthNames[currentMonth]}
- +
diff --git a/apps/frontend/src/components/calendarStyles.ts b/apps/frontend/src/components/calendarStyles.ts index 59443da..7ae53eb 100644 --- a/apps/frontend/src/components/calendarStyles.ts +++ b/apps/frontend/src/components/calendarStyles.ts @@ -8,9 +8,10 @@ export const styles = { calendarHeader: { display: 'flex', alignItems: 'center', + justifyContent: 'space-between', marginBottom: '0.625rem', borderRadius: '0.5rem', - width: '11rem', + width: '12.5rem', padding: '0.25rem', backgroundColor: '#7eb397', borderColor: '#18633d', @@ -23,6 +24,7 @@ export const styles = { paddingBottom: '0.25rem', fontSize: '1.125rem', fontWeight: 'bold', + cursor: 'pointer', }, monthLabel: { fontSize: '1.25rem', From 99b4b25669e48ae3cf889d400317c9bda43879f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Wed, 11 Sep 2024 17:07:09 +0200 Subject: [PATCH 5/8] some fixes on rendering and mobile view --- apps/frontend/src/app/calendarPage/page.tsx | 31 ++++++++++++++----- .../frontend/src/components/calendarStyles.ts | 6 ++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/apps/frontend/src/app/calendarPage/page.tsx b/apps/frontend/src/app/calendarPage/page.tsx index 09ab92d..7ddb57e 100644 --- a/apps/frontend/src/app/calendarPage/page.tsx +++ b/apps/frontend/src/app/calendarPage/page.tsx @@ -1,11 +1,13 @@ 'use client'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { styles } from '@/components/calendarStyles'; // Segédfüggvények const daysInWeek = ['Hétfő', 'Kedd', 'Szerda', 'Csütörtök', 'Péntek', 'Szombat', 'Vasárnap']; +const shortDaysInWeek = ['H', 'K', 'Sz', 'Cs', 'P', 'Sz', 'V']; + const monthNames = [ 'Január', 'Február', @@ -26,20 +28,35 @@ const getDaysInMonth = (month: number, year: number) => { }; const getFirstDayOfMonth = (month: number, year: number) => { - return new Date(year, month, 1).getDay(); + const day = new Date(year, month, 1).getDay(); + return day === 0 ? 7 : day; }; // Calendar komponens const Calendar: React.FC = () => { const [currentMonth, setCurrentMonth] = useState(7); // Augusztus const [currentYear, setCurrentYear] = useState(2024); // 2024 + const [isMobile, setIsMobile] = useState(false); + + // Ellenőrizze, hogy mobilon vagyunk-e + useEffect(() => { + const handleResize = () => { + setIsMobile(window.innerWidth <= 600); + }; + + window.addEventListener('resize', handleResize); + handleResize(); // Csak egyszer hívjuk meg, amikor a komponens betöltődik + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); const daysInMonth = getDaysInMonth(currentMonth, currentYear); const firstDayOfMonth = getFirstDayOfMonth(currentMonth, currentYear); const handlePrevMonth = () => { if (currentMonth === 0) { - // Ha január van, lépj vissza decemberre és csökkentsd az évet setCurrentMonth(11); setCurrentYear(currentYear - 1); } else { @@ -49,7 +66,6 @@ const Calendar: React.FC = () => { const handleNextMonth = () => { if (currentMonth === 11) { - // Ha december van, lépj előre januárra és növeld az évet setCurrentMonth(0); setCurrentYear(currentYear + 1); } else { @@ -68,7 +84,7 @@ const Calendar: React.FC = () => { // A hónap napjai for (let i = 1; i <= daysInMonth; i++) { days.push( -
+
{i}
); @@ -97,8 +113,9 @@ const Calendar: React.FC = () => {
- {daysInWeek.map((day) => ( -
+ {(isMobile ? shortDaysInWeek : daysInWeek).map((day, index) => ( + // eslint-disable-next-line react/no-array-index-key +
{day}
))} diff --git a/apps/frontend/src/components/calendarStyles.ts b/apps/frontend/src/components/calendarStyles.ts index 7ae53eb..73b3744 100644 --- a/apps/frontend/src/components/calendarStyles.ts +++ b/apps/frontend/src/components/calendarStyles.ts @@ -3,7 +3,13 @@ export const styles = { marginTop: '1.25rem', width: '91.666667%', marginLeft: '4rem', + marginRight: '4rem', fontFamily: 'sans-serif', + '@media (max-width: 600px)': { + marginLeft: '1rem', + marginRight: '1rem', + width: '95%', + }, }, calendarHeader: { display: 'flex', From 7aed2dec0335246e7a1b4a2c76c22d09d5b990d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Wed, 11 Sep 2024 17:27:32 +0200 Subject: [PATCH 6/8] Revert "conflicts solved" This reverts commit 668c7842d5997ae6649a1a4477227ab904256a8f, reversing changes made to 99b4b25669e48ae3cf889d400317c9bda43879f2. --- apps/backend/.env.example | 1 - apps/backend/package.json | 3 +- .../backend/src/event/entity/event.details.ts | 7 -- apps/backend/src/event/entity/event.entity.ts | 1 - apps/backend/src/event/event.service.ts | 29 ++------ apps/backend/src/main.ts | 7 -- apps/backend/src/users/dto/create-user.dto.ts | 4 +- apps/backend/src/users/entities/PublicUser.ts | 4 -- .../backend/src/users/entities/UserDetails.ts | 11 --- .../backend/src/users/entities/user.entity.ts | 2 +- apps/backend/src/users/users.controller.ts | 4 +- apps/backend/src/users/users.service.ts | 18 ++--- apps/frontend/package.json | 10 +-- .../src/api/hooks/eventMutationHooks.ts | 12 ---- .../frontend/src/api/hooks/eventQueryHooks.ts | 13 ---- apps/frontend/src/api/model/comment.model.ts | 5 -- apps/frontend/src/api/model/event.model.ts | 38 ---------- .../frontend/src/api/model/organizer.model.ts | 3 - apps/frontend/src/api/model/owner.model.ts | 3 - apps/frontend/src/app/events/[id]/page.tsx | 71 ------------------- apps/frontend/src/app/events/page.tsx | 3 - .../src/app/events/types/createEvent.ts | 27 ------- .../src/app/events/types/eventDetails.ts | 8 --- apps/frontend/src/app/layout.tsx | 16 ++--- apps/frontend/src/app/newEvent/page.tsx | 54 ++++++++++++++ .../src/app/users/types/PublicUser.ts | 4 -- apps/frontend/src/{util => lib}/utils.ts | 6 -- apps/frontend/src/util/environment.ts | 2 - apps/frontend/src/util/query-client.ts | 9 --- ideas.txt | 3 - 30 files changed, 80 insertions(+), 298 deletions(-) delete mode 100644 apps/backend/src/event/entity/event.details.ts delete mode 100644 apps/backend/src/users/entities/PublicUser.ts delete mode 100644 apps/backend/src/users/entities/UserDetails.ts delete mode 100644 apps/frontend/src/api/hooks/eventMutationHooks.ts delete mode 100644 apps/frontend/src/api/hooks/eventQueryHooks.ts delete mode 100644 apps/frontend/src/api/model/comment.model.ts delete mode 100644 apps/frontend/src/api/model/event.model.ts delete mode 100644 apps/frontend/src/api/model/organizer.model.ts delete mode 100644 apps/frontend/src/api/model/owner.model.ts delete mode 100644 apps/frontend/src/app/events/[id]/page.tsx delete mode 100644 apps/frontend/src/app/events/page.tsx delete mode 100644 apps/frontend/src/app/events/types/createEvent.ts delete mode 100644 apps/frontend/src/app/events/types/eventDetails.ts create mode 100644 apps/frontend/src/app/newEvent/page.tsx delete mode 100644 apps/frontend/src/app/users/types/PublicUser.ts rename apps/frontend/src/{util => lib}/utils.ts (55%) delete mode 100644 apps/frontend/src/util/environment.ts delete mode 100644 apps/frontend/src/util/query-client.ts delete mode 100644 ideas.txt diff --git a/apps/backend/.env.example b/apps/backend/.env.example index 9e20272..96cf925 100644 --- a/apps/backend/.env.example +++ b/apps/backend/.env.example @@ -1,2 +1 @@ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public" -FRONTEND_HOST="http://localhost:3000" diff --git a/apps/backend/package.json b/apps/backend/package.json index 55ed729..e3f2dfc 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -18,7 +18,7 @@ "@nestjs/core": "^10.3.8", "@nestjs/platform-express": "^10.3.8", "@nestjs/swagger": "^7.3.1", - "@prisma/client": "^5.18.0", + "@prisma/client": "^5.13.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.1", "nestjs-prisma": "^0.23.0", @@ -35,7 +35,6 @@ "@types/node": "^20.12.7", "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", - "prisma": "^5.18.0", "source-map-support": "^0.5.21", "ts-loader": "^9.5.1", "ts-node": "^10.9.2", diff --git a/apps/backend/src/event/entity/event.details.ts b/apps/backend/src/event/entity/event.details.ts deleted file mode 100644 index 18e33f9..0000000 --- a/apps/backend/src/event/entity/event.details.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { PublicUser } from '../../users/entities/PublicUser'; -import { Event } from './event.entity'; - -export class EventDetailsDto extends Event { - owner: PublicUser; - organizers: PublicUser[]; -} diff --git a/apps/backend/src/event/entity/event.entity.ts b/apps/backend/src/event/entity/event.entity.ts index b35a5ea..abf3623 100644 --- a/apps/backend/src/event/entity/event.entity.ts +++ b/apps/backend/src/event/entity/event.entity.ts @@ -35,7 +35,6 @@ export class Event { color: Color; @IsNotEmpty() - @IsEnum(Status) status: Status; @IsString() diff --git a/apps/backend/src/event/event.service.ts b/apps/backend/src/event/event.service.ts index 14b8680..80dffe6 100644 --- a/apps/backend/src/event/event.service.ts +++ b/apps/backend/src/event/event.service.ts @@ -4,7 +4,6 @@ import { PrismaService } from 'nestjs-prisma'; import { CreateEventDto } from './dto/create-event.dto'; import { UpdateEventDto } from './dto/update-event.dto'; -import { EventDetailsDto } from './entity/event.details'; import { Event } from './entity/event.entity'; @Injectable() @@ -12,25 +11,12 @@ export class EventService { constructor(private readonly prisma: PrismaService) {} async create(data: CreateEventDto): Promise { - const { ownerId, ...restOfData } = data; try { - return await this.prisma.event.create({ - data: { - ...restOfData, - owner: { - connect: { - authSchId: ownerId, - }, - }, - }, - }); + return await this.prisma.event.create({ data }); } catch (error) { if (error instanceof PrismaClientValidationError) { throw new BadRequestException(`Invalid data`); } - if (error instanceof PrismaClientKnownRequestError) { - if (error.code === 'P2002') throw new BadRequestException(`Invalid data: user not found`); - } throw error; } } @@ -39,15 +25,9 @@ export class EventService { return this.prisma.event.findMany(); } - async findOne(id: string): Promise { + async findOne(id: string): Promise { try { - return await this.prisma.event.findUnique({ - where: { id }, - include: { - owner: true, - organizers: true, - }, - }); + return await this.prisma.event.findUnique({ where: { id } }); } catch { throw new NotFoundException(`Event not found`); } @@ -58,8 +38,7 @@ export class EventService { return await this.prisma.event.update({ where: { id }, data }); } catch (error) { if (error instanceof PrismaClientKnownRequestError) { - if (error.code === 'P2002') throw new BadRequestException(`Invalid data: user not found`); - if (error.code === 'P2025') throw new NotFoundException(`Event not found`); + throw new NotFoundException(`Event not found`); } if (error instanceof PrismaClientValidationError) { throw new BadRequestException(`Invalid data`); diff --git a/apps/backend/src/main.ts b/apps/backend/src/main.ts index c510d29..9c29891 100644 --- a/apps/backend/src/main.ts +++ b/apps/backend/src/main.ts @@ -1,18 +1,11 @@ import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; -import cors from 'cors'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.useGlobalPipes(new ValidationPipe({ whitelist: true })); - app.use( - cors({ - origin: process.env.FRONTEND_HOST, - credentials: true, - }) - ); await app.listen(3001); } bootstrap(); diff --git a/apps/backend/src/users/dto/create-user.dto.ts b/apps/backend/src/users/dto/create-user.dto.ts index 41c8134..113bf42 100644 --- a/apps/backend/src/users/dto/create-user.dto.ts +++ b/apps/backend/src/users/dto/create-user.dto.ts @@ -1,5 +1,5 @@ import { OmitType } from '@nestjs/swagger'; -import { UserEntity } from '../entities/user.entity'; +import { User } from '../entities/user.entity'; -export class CreateUserDto extends OmitType(UserEntity, ['isAdmin']) {} +export class CreateUserDto extends OmitType(User, ['isAdmin']) {} diff --git a/apps/backend/src/users/entities/PublicUser.ts b/apps/backend/src/users/entities/PublicUser.ts deleted file mode 100644 index 6c05f72..0000000 --- a/apps/backend/src/users/entities/PublicUser.ts +++ /dev/null @@ -1,4 +0,0 @@ -export class PublicUser { - authSchId: string; - name: string; -} diff --git a/apps/backend/src/users/entities/UserDetails.ts b/apps/backend/src/users/entities/UserDetails.ts deleted file mode 100644 index 0bfcb61..0000000 --- a/apps/backend/src/users/entities/UserDetails.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Event } from '../../event/entity/event.entity'; -import { PublicUser } from './PublicUser'; - -export class UserDetails extends PublicUser { - isAdmin: boolean; - nickname: string; - email: string; - phone: string; - ownedEvents: Event[]; - organizedEvents: Event[]; -} diff --git a/apps/backend/src/users/entities/user.entity.ts b/apps/backend/src/users/entities/user.entity.ts index 5d55c85..0145fa7 100644 --- a/apps/backend/src/users/entities/user.entity.ts +++ b/apps/backend/src/users/entities/user.entity.ts @@ -1,6 +1,6 @@ import { IsBoolean, IsEmail, IsNotEmpty, IsString } from 'class-validator'; -export class UserEntity { +export class User { @IsString() @IsNotEmpty() authSchId: string; diff --git a/apps/backend/src/users/users.controller.ts b/apps/backend/src/users/users.controller.ts index b4f3ce7..95ab93c 100644 --- a/apps/backend/src/users/users.controller.ts +++ b/apps/backend/src/users/users.controller.ts @@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/commo import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; -import { UserEntity } from './entities/user.entity'; +import { User } from './entities/user.entity'; import { UsersService } from './users.service'; @Controller('users') @@ -10,7 +10,7 @@ export class UsersController { constructor(private readonly usersService: UsersService) {} @Post() - create(@Body() data: CreateUserDto): Promise { + create(@Body() data: CreateUserDto): Promise { return this.usersService.create(data); } diff --git a/apps/backend/src/users/users.service.ts b/apps/backend/src/users/users.service.ts index 22837f8..f4012af 100644 --- a/apps/backend/src/users/users.service.ts +++ b/apps/backend/src/users/users.service.ts @@ -4,31 +4,28 @@ import { PrismaService } from 'nestjs-prisma'; import { CreateUserDto } from './dto/create-user.dto'; import { UpdateUserDto } from './dto/update-user.dto'; -import { UserEntity } from './entities/user.entity'; +import { User } from './entities/user.entity'; @Injectable() export class UsersService { constructor(private readonly prisma: PrismaService) {} - async create(data: CreateUserDto): Promise { + async create(data: CreateUserDto): Promise { try { return await this.prisma.user.create({ data }); } catch (error) { if (error instanceof PrismaClientValidationError) { throw new BadRequestException('Invalid User data'); } - if (error instanceof PrismaClientKnownRequestError) { - if (error.code === 'P2002') throw new BadRequestException(`Invalid User data: email already in use`); - } throw error; } } - async findAll(): Promise { + async findAll(): Promise { return this.prisma.user.findMany(); } - async findOne(id: string): Promise { + async findOne(id: string): Promise { const user = await this.prisma.user.findUnique({ where: { authSchId: id } }); if (user === null) { throw new NotFoundException('User not found'); @@ -36,13 +33,12 @@ export class UsersService { return user; } - async update(id: string, data: UpdateUserDto): Promise { + async update(id: string, data: UpdateUserDto): Promise { try { return await this.prisma.user.update({ where: { authSchId: id }, data }); } catch (error) { if (error instanceof PrismaClientKnownRequestError) { - if (error.code === 'P2002') throw new BadRequestException(`Invalid data: email already in use`); - if (error.code === 'P2025') throw new NotFoundException(`User not found`); + throw new NotFoundException(`User not found`); } if (error instanceof PrismaClientValidationError) { throw new BadRequestException(`Invalid data`); @@ -51,7 +47,7 @@ export class UsersService { } } - async delete(id: string): Promise { + async delete(id: string): Promise { try { return await this.prisma.user.delete({ where: { authSchId: id } }); } catch { diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 4984bd2..22eb17c 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -12,18 +12,12 @@ "lint": "next lint" }, "dependencies": { - "@tanstack/react-query": "^5.51.15", - "@tanstack/react-query-devtools": "^5.51.23", - "axios": "^1.7.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "lucide-react": "^0.372.0", "next": "14.2.2", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-hook-form": "^7.52.2", - "react-icons": "^5.2.1", - "react-router-dom": "^6.25.1", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7" }, @@ -31,9 +25,9 @@ "@types/node": "^20.12.7", "@types/react": "^18.2.79", "@types/react-dom": "^18.2.25", - "eslint-plugin-react": "^7.34.1", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", - "typescript": "^5.4.5" + "typescript": "^5.4.5", + "eslint-plugin-react": "^7.34.1" } } diff --git a/apps/frontend/src/api/hooks/eventMutationHooks.ts b/apps/frontend/src/api/hooks/eventMutationHooks.ts deleted file mode 100644 index ddc62a9..0000000 --- a/apps/frontend/src/api/hooks/eventMutationHooks.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useMutation } from '@tanstack/react-query'; -import axios from 'axios'; - -import { EventModel } from '@/api/model/event.model'; -import { CreateEvent } from '@/app/events/types/createEvent'; -import { API_HOST } from '@/util/environment'; - -export const useCreateEventMutation = () => { - return useMutation({ - mutationFn: async (event: CreateEvent) => (await axios.post(`${API_HOST}/events`, event)).data, - }); -}; diff --git a/apps/frontend/src/api/hooks/eventQueryHooks.ts b/apps/frontend/src/api/hooks/eventQueryHooks.ts deleted file mode 100644 index d134e45..0000000 --- a/apps/frontend/src/api/hooks/eventQueryHooks.ts +++ /dev/null @@ -1,13 +0,0 @@ -'use client'; -import { useQuery } from '@tanstack/react-query'; -import axios from 'axios'; - -import { EventDetails } from '@/app/events/types/eventDetails'; -import { API_HOST } from '@/util/environment'; - -export const useFetchEventDetailsQuery = (eventId: string) => { - return useQuery({ - queryKey: ['fetchEventDetails', eventId], - queryFn: async () => (await axios.get(`${API_HOST}/events/${eventId}`)).data, - }); -}; diff --git a/apps/frontend/src/api/model/comment.model.ts b/apps/frontend/src/api/model/comment.model.ts deleted file mode 100644 index 774fd20..0000000 --- a/apps/frontend/src/api/model/comment.model.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface CommentModel { - id: number; - text: string; - createdAt: Date; -} diff --git a/apps/frontend/src/api/model/event.model.ts b/apps/frontend/src/api/model/event.model.ts deleted file mode 100644 index 9f15af7..0000000 --- a/apps/frontend/src/api/model/event.model.ts +++ /dev/null @@ -1,38 +0,0 @@ -export enum Priority { - SZINT, - KAJAS, - KOR, - HAZ, - EGYETEM, - NOTGIVEN, -} - -export enum Status { - CREATED, - SUBMITTED, - APPROVED, -} - -export enum Color { - RED = 'RED', - ORANGE = 'ORANGE', - YELLOW = 'YELLOW', - GREEN = 'GREEN', - BLUE = 'BLUE', - PURPLE = 'PURPLE', -} - -export type EventModel = { - id: string; - name: string; - description: string; - date: string; //TODO startDate+endDate? - location: string; - tags: string[]; - messages: string[]; //TODO külön reláció a kommenteknek? - priority: Priority; - color: Color; - status: Status; - createdAt?: string; - link?: string; -}; diff --git a/apps/frontend/src/api/model/organizer.model.ts b/apps/frontend/src/api/model/organizer.model.ts deleted file mode 100644 index c0b5147..0000000 --- a/apps/frontend/src/api/model/organizer.model.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface OrganizerModel { - id: number; -} diff --git a/apps/frontend/src/api/model/owner.model.ts b/apps/frontend/src/api/model/owner.model.ts deleted file mode 100644 index 0c2df54..0000000 --- a/apps/frontend/src/api/model/owner.model.ts +++ /dev/null @@ -1,3 +0,0 @@ -export interface OwnerModel { - id: number; -} diff --git a/apps/frontend/src/app/events/[id]/page.tsx b/apps/frontend/src/app/events/[id]/page.tsx deleted file mode 100644 index 4023aa0..0000000 --- a/apps/frontend/src/app/events/[id]/page.tsx +++ /dev/null @@ -1,71 +0,0 @@ -'use client'; -import { FaLocationDot } from 'react-icons/fa6'; -import { MdLink, MdOutlineDateRange, MdPeople } from 'react-icons/md'; - -import { useFetchEventDetailsQuery } from '@/api/hooks/eventQueryHooks'; -import Home from '@/app/page'; - -export default function EventDetailsPage({ params }: { params: { id: string } }) { - const { data: event, error: e } = useFetchEventDetailsQuery(params.id!); - - if (e) { - throw e; - } - - if (!event) { - return ; - } - - return ( -
-
- {/*left side*/} -
-

{event?.name}

-
-
- -

{event?.date}

-
-
- -

{event?.location}

-
-
- {event?.tags?.map((tag, index) => { - return ( -
- {tag} -
- ); - })} -
-
- -

Organizers

-
-
    - {event?.organizers?.map((organizer) => { - return
  • {organizer?.name}
  • ; - })} -
-
- -

{event?.link}

-
-
-
-
-

{event?.description}

-
-
-
-

Comments

-

{event?.messages.length}

-
- {event?.messages?.map((message, index) =>

{message}

)} -
-
-
- ); -} diff --git a/apps/frontend/src/app/events/page.tsx b/apps/frontend/src/app/events/page.tsx deleted file mode 100644 index b97156b..0000000 --- a/apps/frontend/src/app/events/page.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function EventList() { - return

Events

; -} diff --git a/apps/frontend/src/app/events/types/createEvent.ts b/apps/frontend/src/app/events/types/createEvent.ts deleted file mode 100644 index 42b4cf7..0000000 --- a/apps/frontend/src/app/events/types/createEvent.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Color, Status } from '@/api/model/event.model'; -import { PublicUser } from '@/app/users/types/PublicUser'; - -export interface CreateEvent { - name: string; - description: string; - date: Date; - location: string; - tags: string[]; - //organizerIds: string[]; - color: Color; - status: Status; - ownerId: string; - link?: string; -} - -export type CreateEventForm = { - name: string; - description: string; - date: Date; - location: string; - tags: string[]; - //organizers: PublicUser[]; - color: Color; - //status: Status; - link?: string; -}; diff --git a/apps/frontend/src/app/events/types/eventDetails.ts b/apps/frontend/src/app/events/types/eventDetails.ts deleted file mode 100644 index 67cb606..0000000 --- a/apps/frontend/src/app/events/types/eventDetails.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { EventModel } from '@/api/model/event.model'; -import { PublicUser } from '@/app/users/types/PublicUser'; - -export type EventDetails = EventModel & { - owner: PublicUser; - organizers: PublicUser[]; - //comments: CommentModel[]; -}; diff --git a/apps/frontend/src/app/layout.tsx b/apps/frontend/src/app/layout.tsx index e3748cc..f9d1c85 100644 --- a/apps/frontend/src/app/layout.tsx +++ b/apps/frontend/src/app/layout.tsx @@ -1,12 +1,13 @@ -'use client'; import './globals.css'; -import { QueryClientProvider } from '@tanstack/react-query'; -import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import type { Metadata } from 'next'; import Navbar from '@/components/navbar'; -import { queryClient } from '@/util/query-client'; + +export const metadata: Metadata = { + title: 'ProgramSCH', + description: 'created by KirDev', +}; export default function RootLayout({ children, @@ -16,11 +17,8 @@ export default function RootLayout({ return ( - - - {children} - - + + {children} ); diff --git a/apps/frontend/src/app/newEvent/page.tsx b/apps/frontend/src/app/newEvent/page.tsx new file mode 100644 index 0000000..e00add9 --- /dev/null +++ b/apps/frontend/src/app/newEvent/page.tsx @@ -0,0 +1,54 @@ +import Button from '@/components/button'; +import Input from '@/components/input'; +import { styles } from '@/components/newEventStyles'; + +export default function newEvent() { + return ( +
+
+
+ Event létrehozása +
+
+
+ Név: + +
+
+ Szín: +
+
+
+
+ Helyszín: + +
+
+ Tagek: + +
+
+
+
+ Időpont: + +
+
+ Szervezők: + +
+
+
+ Leírás: +
+ +
+
+
+
+
+
+ ); +} diff --git a/apps/frontend/src/app/users/types/PublicUser.ts b/apps/frontend/src/app/users/types/PublicUser.ts deleted file mode 100644 index 0741a73..0000000 --- a/apps/frontend/src/app/users/types/PublicUser.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface PublicUser { - authSchId: string; - name: string; -} diff --git a/apps/frontend/src/util/utils.ts b/apps/frontend/src/lib/utils.ts similarity index 55% rename from apps/frontend/src/util/utils.ts rename to apps/frontend/src/lib/utils.ts index 13f3541..9ad0df4 100644 --- a/apps/frontend/src/util/utils.ts +++ b/apps/frontend/src/lib/utils.ts @@ -1,12 +1,6 @@ import { type ClassValue, clsx } from 'clsx'; import { twMerge } from 'tailwind-merge'; -import type { Metadata } from 'next'; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } - -export const metadata: Metadata = { - title: 'ProgramSCH', - description: 'created by KirDev', -}; diff --git a/apps/frontend/src/util/environment.ts b/apps/frontend/src/util/environment.ts deleted file mode 100644 index 71f6954..0000000 --- a/apps/frontend/src/util/environment.ts +++ /dev/null @@ -1,2 +0,0 @@ -export const API_HOST = 'http://localhost:3001'; -export const FRONTEND_HOST = 'http://localhost:3000'; diff --git a/apps/frontend/src/util/query-client.ts b/apps/frontend/src/util/query-client.ts deleted file mode 100644 index cebc6d2..0000000 --- a/apps/frontend/src/util/query-client.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { QueryClient } from '@tanstack/react-query'; - -export const queryClient = new QueryClient({ - defaultOptions: { - queries: { - refetchOnWindowFocus: false, - }, - }, -}); diff --git a/ideas.txt b/ideas.txt deleted file mode 100644 index 008bf5e..0000000 --- a/ideas.txt +++ /dev/null @@ -1,3 +0,0 @@ -Event.messages: legyen látható hogy ki írta? - ezt akkor csak külön relációval lehetne hatékonyan - From 38aef798b1edaea266c61239dceb7c75a7dff8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Wed, 11 Sep 2024 17:33:18 +0200 Subject: [PATCH 7/8] accidentally deleated file is back --- apps/frontend/src/app/events/new/page.tsx | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 apps/frontend/src/app/events/new/page.tsx diff --git a/apps/frontend/src/app/events/new/page.tsx b/apps/frontend/src/app/events/new/page.tsx new file mode 100644 index 0000000..9aca2c7 --- /dev/null +++ b/apps/frontend/src/app/events/new/page.tsx @@ -0,0 +1,102 @@ +import { redirect } from 'next/navigation'; +import { useForm } from 'react-hook-form'; + +import { useCreateEventMutation } from '@/api/hooks/eventMutationHooks'; +import { Color, EventModel, Status } from '@/api/model/event.model'; +import { CreateEvent, CreateEventForm } from '@/app/events/types/createEvent'; +import Button from '@/components/button'; +import Input from '@/components/input'; +import { styles } from '@/components/newEventStyles'; + +export default function newEvent() { + const { mutate: createEvent } = useCreateEventMutation(); + const publishEvent = (formData: CreateEvent) => { + createEvent(formData, { + onSuccess: (event: EventModel) => { + redirect(`http://localhost:3000/events/${event.id}`); + }, + }); + }; + + const form = useForm({ + defaultValues: { + tags: [], + date: new Date(), + color: Color.RED, + }, + mode: 'all', + }); + + const { + register, + handleSubmit, + setValue, + watch, + resetField, + formState: { errors, isValid, isSubmitted }, + } = form; + + const onSubmit = handleSubmit((data: CreateEventForm) => { + const formData: CreateEvent = { + name: data.name, + description: data.description, + date: data.date, + location: data.location, + tags: data.tags, + color: data.color, + link: data.link, + ownerId: 'bearni03', + status: Status.SUBMITTED, + }; + publishEvent(formData); + }); + + return ( +
+
+
+ Event létrehozása +
+
+
+ Név: + +
+
+ Szín: +
+
+
+
+ Helyszín: + +
+
+ Tagek: + +
+
+
+
+ Időpont: + +
+
+ Szervezők: + +
+
+
+ Leírás: +
+ +
+
+
+
+
+
+ ); +} From a7bc8ae665b5f155c74d987034ef9c634b1db726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sali=20N=C3=B3ra?= Date: Wed, 11 Sep 2024 17:33:18 +0200 Subject: [PATCH 8/8] accidentally deleted file is back --- apps/frontend/src/app/events/new/page.tsx | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 apps/frontend/src/app/events/new/page.tsx diff --git a/apps/frontend/src/app/events/new/page.tsx b/apps/frontend/src/app/events/new/page.tsx new file mode 100644 index 0000000..9aca2c7 --- /dev/null +++ b/apps/frontend/src/app/events/new/page.tsx @@ -0,0 +1,102 @@ +import { redirect } from 'next/navigation'; +import { useForm } from 'react-hook-form'; + +import { useCreateEventMutation } from '@/api/hooks/eventMutationHooks'; +import { Color, EventModel, Status } from '@/api/model/event.model'; +import { CreateEvent, CreateEventForm } from '@/app/events/types/createEvent'; +import Button from '@/components/button'; +import Input from '@/components/input'; +import { styles } from '@/components/newEventStyles'; + +export default function newEvent() { + const { mutate: createEvent } = useCreateEventMutation(); + const publishEvent = (formData: CreateEvent) => { + createEvent(formData, { + onSuccess: (event: EventModel) => { + redirect(`http://localhost:3000/events/${event.id}`); + }, + }); + }; + + const form = useForm({ + defaultValues: { + tags: [], + date: new Date(), + color: Color.RED, + }, + mode: 'all', + }); + + const { + register, + handleSubmit, + setValue, + watch, + resetField, + formState: { errors, isValid, isSubmitted }, + } = form; + + const onSubmit = handleSubmit((data: CreateEventForm) => { + const formData: CreateEvent = { + name: data.name, + description: data.description, + date: data.date, + location: data.location, + tags: data.tags, + color: data.color, + link: data.link, + ownerId: 'bearni03', + status: Status.SUBMITTED, + }; + publishEvent(formData); + }); + + return ( +
+
+
+ Event létrehozása +
+
+
+ Név: + +
+
+ Szín: +
+
+
+
+ Helyszín: + +
+
+ Tagek: + +
+
+
+
+ Időpont: + +
+
+ Szervezők: + +
+
+
+ Leírás: +
+ +
+
+
+
+
+
+ ); +}