Skip to content

feature/news page #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6324c24
created members page
justnyx Mar 17, 2025
ad549d4
fixed git ignore
justnyx Mar 17, 2025
f406779
fixed eslint issue
justnyx Mar 17, 2025
7d8eabb
new tile design
justnyx Jun 17, 2025
6fe6079
created stats page
justnyx Jun 17, 2025
0a48c56
created rules page
justnyx Jun 18, 2025
5830f38
made sidebar interactive
justnyx Jun 18, 2025
e57c709
created news page
justnyx Jun 19, 2025
32a35a0
modified sidebar
justnyx Jun 19, 2025
007d065
modified pagination buttons
justnyx Jun 19, 2025
fb4218b
use popup form for post create and edit
justnyx Jun 25, 2025
dc5e9ef
backend functionality for posts
justnyx Jun 25, 2025
e0477b9
reverted backed
justnyx Jul 3, 2025
12ff60c
posts generated
mozsarmate Jul 3, 2025
71545ff
dto s
mozsarmate Jul 3, 2025
d3ed24c
posts controller and service
justnyx Jul 3, 2025
fa6150c
Merge branch 'feature/news_page' of https://github.com/kir-dev/mmmk-w…
justnyx Jul 3, 2025
ef95f92
swr
mozsarmate Jul 3, 2025
553bc19
Merge remote-tracking branch 'origin/feature/news_page' into feature/…
mozsarmate Jul 3, 2025
dcbdeb0
fix + cors + page
mozsarmate Jul 3, 2025
bc5fc66
connection
mozsarmate Jul 3, 2025
af922ce
added swr
justnyx Jul 3, 2025
a627733
Merge branch 'feature/news_page' of https://github.com/kir-dev/mmmk-w…
justnyx Jul 3, 2025
43f4797
posts are now connected to the backend
justnyx Jul 7, 2025
9d73d8c
Merge branch 'main' into feature/news_page
justnyx Jul 7, 2025
f945bdd
fixed eslint error
justnyx Jul 7, 2025
79bb3c9
fixed pagiantion
justnyx Jul 7, 2025
f3aee1e
made /news the root page
justnyx Jul 7, 2025
e3f2045
refactored news page
justnyx Jul 7, 2025
219bff0
made page header sticky
justnyx Jul 7, 2025
8f40757
renamed file
justnyx Jul 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .env.example

This file was deleted.

1 change: 0 additions & 1 deletion apps/backend/.env.example

This file was deleted.

13 changes: 13 additions & 0 deletions apps/backend/prisma/migrations/20250703183905_posts/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE "Post" (
"id" SERIAL NOT NULL,
"title" TEXT NOT NULL,
"body" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"authorId" INTEGER NOT NULL,

CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
10 changes: 10 additions & 0 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ model User {
profilePicture ProfilePicture?
gateKeeping Reservation[] @relation("GateKeeping")
reservations Reservation[] @relation("Reservations")
posts Post[]
}

model ProfilePicture {
Expand Down Expand Up @@ -83,6 +84,15 @@ model Period {
endDate DateTime
}

model Post {
id Int @id @default(autoincrement())
title String
body String
createdAt DateTime @default(now())
author User @relation(fields: [authorId], references: [id])
authorId Int
}

enum Role {
USER
GATEKEEPER
Expand Down
10 changes: 9 additions & 1 deletion apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { BandsModule } from './bands/bandsModule';
import { CommentsModule } from './comments/comments.module';
import { PostsModule } from './posts/posts.module';
import { ReservationsModule } from './reservations/reservations.module';
import { UsersModule } from './users/users.module';

@Module({
imports: [PrismaModule.forRoot({ isGlobal: true }), UsersModule, ReservationsModule, CommentsModule, BandsModule],
imports: [
PrismaModule.forRoot({ isGlobal: true }),
UsersModule,
ReservationsModule,
CommentsModule,
BandsModule,
PostsModule,
],
controllers: [AppController],
providers: [AppService],
})
Expand Down
6 changes: 6 additions & 0 deletions apps/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ async function bootstrap() {
whitelist: true,
})
);
app.enableCors({
origin: [process.env.FRONTEND_URL, 'http://localhost:3000', RegExp('([a-zA-Z0-9-]+)*kir-dev.vercel.app/')],
methods: ['GET', 'POST', 'PATCH', 'DELETE', 'PUT'],
credentials: true,
});
await app.listen(3001);
}

bootstrap();
5 changes: 5 additions & 0 deletions apps/backend/src/posts/dto/create-post.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { OmitType } from '@nestjs/swagger';

import { Post } from '../entities/post.entity';

export class CreatePostDto extends OmitType(Post, ['id', 'createdAt']) {}
5 changes: 5 additions & 0 deletions apps/backend/src/posts/dto/update-post.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PartialType } from '@nestjs/swagger';

import { CreatePostDto } from './create-post.dto';

export class UpdatePostDto extends PartialType(CreatePostDto) {}
21 changes: 21 additions & 0 deletions apps/backend/src/posts/entities/post.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IsDate, IsNotEmpty, IsNumber, IsString } from 'class-validator';

export class Post {
@IsNotEmpty()
@IsNumber()
id: number;

@IsNotEmpty()
@IsString()
title: string;

@IsString()
body: string;

@IsNotEmpty()
@IsDate()
createdAt: Date;

@IsNumber()
authorId: number;
}
35 changes: 35 additions & 0 deletions apps/backend/src/posts/posts.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Body, Controller, Delete, Get, Param, ParseIntPipe, Patch, Post, Query } from '@nestjs/common';

import { CreatePostDto } from './dto/create-post.dto';
import { UpdatePostDto } from './dto/update-post.dto';
import { PostsService } from './posts.service';

@Controller('posts')
export class PostsController {
constructor(private readonly postsService: PostsService) {}

@Post()
create(@Body() createPostDto: CreatePostDto) {
return this.postsService.create(createPostDto);
}

@Get()
findAll(@Query('page', ParseIntPipe) page: number, @Query('page_size', ParseIntPipe) pageSize: number) {
return this.postsService.findAll(page, pageSize);
}

@Get(':id')
findOne(@Param('id', ParseIntPipe) id: number) {
return this.postsService.findOne(id);
}

@Patch(':id')
update(@Param('id', ParseIntPipe) id: number, @Body() updatePostDto: UpdatePostDto) {
return this.postsService.update(id, updatePostDto);
}

@Delete(':id')
remove(@Param('id', ParseIntPipe) id: number) {
return this.postsService.remove(id);
}
}
10 changes: 10 additions & 0 deletions apps/backend/src/posts/posts.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';

import { PostsController } from './posts.controller';
import { PostsService } from './posts.service';

@Module({
controllers: [PostsController],
providers: [PostsService],
})
export class PostsModule {}
98 changes: 98 additions & 0 deletions apps/backend/src/posts/posts.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { Injectable, InternalServerErrorException, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/client';
import { PrismaService } from 'nestjs-prisma';
import { PaginationDto } from 'src/dto/pagination.dto';

import { CreatePostDto } from './dto/create-post.dto';
import { UpdatePostDto } from './dto/update-post.dto';
import { Post } from './entities/post.entity';

@Injectable()
export class PostsService {
constructor(private readonly prisma: PrismaService) {}

create(createPostDto: CreatePostDto) {
return this.prisma.post.create({
data: {
...createPostDto,
},
});
}

async findAll(page?: number, pageSize?: number): Promise<PaginationDto<Post>> {
const hasPagination = page !== -1 && pageSize !== -1;
const posts = this.prisma.post.findMany({
skip: hasPagination ? (page - 1) * pageSize : undefined,
take: hasPagination ? pageSize : undefined,
});

const count = this.prisma.post.count();

try {
const [postsa, counta] = await Promise.all([posts, count]);
const limit = hasPagination ? Math.floor(counta / pageSize) : 0;
return {
data: postsa,
count: counta,
page,
limit,
};
} catch {
throw new InternalServerErrorException('An error occurred.');
}
}

async findOne(id: number) {
try {
return await this.prisma.post.findUniqueOrThrow({
where: {
id,
},
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
if (e.code === 'P2025') {
throw new NotFoundException(`This post doesn't exist.`);
}
throw new InternalServerErrorException('An error occurred.');
}
}
}

async update(id: number, updatePostDto: UpdatePostDto) {
try {
return await this.prisma.post.update({
where: {
id,
},
data: {
...updatePostDto,
},
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
if (e.code === 'P2025') {
throw new NotFoundException(`This post doesn't exist.`);
}
throw new InternalServerErrorException('An error occurred.');
}
}
}

remove(id: number) {
try {
return this.prisma.post.delete({
where: {
id,
},
});
} catch (e) {
if (e instanceof Prisma.PrismaClientKnownRequestError) {
if (e.code === 'P2025') {
throw new NotFoundException(`This post doesn't exist.`);
}
throw new InternalServerErrorException('An error occurred.');
}
}
}
}
1 change: 1 addition & 0 deletions apps/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NEXT_PUBLIC_API_URL=http://localhost:3001
6 changes: 6 additions & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@
"dependencies": {
"@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.2",
"@radix-ui/react-dialog": "^1.1.14",
"@radix-ui/react-dropdown-menu": "^2.1.2",
"@radix-ui/react-slider": "^1.2.1",
"@radix-ui/react-slot": "^1.1.0",
"@tanstack/react-table": "^8.20.5",
"axios": "^1.10.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"framer-motion": "^11.14.4",
"geist": "^1.3.1",
"js-cookie": "^3.0.5",
"lucide-react": "^0.468.0",
"next": "14.2.13",
"next-themes": "^0.4.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.5.0",
"shadcn": "^2.1.7",
"swr": "^2.3.4",
"tailwind-merge": "^2.5.5",
"tailwindcss-animate": "^1.0.7"
},
"devDependencies": {
"@shadcn/ui": "^0.0.4",
"@types/js-cookie": "^3.0.6",
"@types/node": "^20.12.7",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/app/bands/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { useEffect, useState } from 'react';

import BandRow from '@/components/band/bandRow';
import BandRow from '@/components/band/band-row';
import { Input } from '@/components/ui/input';
import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table';
import { dummyBands } from '@/mocks/bands';
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import './globals.css';
import { GeistSans } from 'geist/font/sans';
import type { Metadata } from 'next';

import { Footer } from '@/components/layout/footer';
import { Header } from '@/components/layout/header';
import { Player } from '@/components/layout/player';
import { RightSidebar } from '@/components/layout/right-sidebar';
import { Sidebar } from '@/components/layout/sidebar';
import { ThemeProvider } from '@/components/theme-provider';
Expand All @@ -30,7 +30,7 @@ export default function RootLayout({
{children}
<RightSidebar />
</div>
<Player />
<Footer />
</div>
</ThemeProvider>
</body>
Expand Down
40 changes: 40 additions & 0 deletions apps/frontend/src/app/members/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use client';

import { Input } from '@components/ui/input';
import { useEffect, useState } from 'react';

import MemberTile from '@/components/member/member-tile';
import { mockUsers } from '@/mocks/users';

export default function Members() {
const data = mockUsers; //TODO: replace with real data
const [filteredData, setFilteredData] = useState(data);
const [searchTerm, setSearchTerm] = useState('');

useEffect(() => {
setFilteredData(data.filter((user) => user.name.toLowerCase().includes(searchTerm.toLowerCase())));
}, [searchTerm]);

return (
<div className='w-full'>
<div className='flex items-center justify-between flex-row p-4'>
<h1 className='text-2xl font-semibold text-primary'>Felhasználók</h1>
<Input
placeholder='Keresés...'
value={searchTerm}
onChange={(event) => setSearchTerm(event.target.value)}
className='max-w-sm target:ring-0'
/>
</div>
{filteredData.length ? (
<div className='grid gap-4 py-4 auto-rows-fr grid-cols-[repeat(auto-fit,minmax(240px,1fr))]'>
{filteredData.map((user) => (
<MemberTile user={user} key={user.id} />
))}
</div>
) : (
<div className='h-24 flex items-center justify-center text-center'>Nincs találat.</div>
)}
</div>
);
}
4 changes: 2 additions & 2 deletions apps/frontend/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MainContent } from '@/components/main-content';
import News from '../components/news/news-page';

export default function Home() {
return <MainContent />;
return <News />;
}
Loading