feat: add comments functionality and integrate Socket.io for real-time updates
- Implemented a full comments module in the backend with repository, service, controller, and DTOs using NestJS. - Added frontend support for comments with a `CommentSection` component and integration into content pages. - Introduced `SocketProvider` on the frontend and integrated Socket.io for real-time communication. - Updated dependencies and configurations for Socket.io and WebSockets support.
This commit is contained in:
41
backend/src/comments/comments.controller.ts
Normal file
41
backend/src/comments/comments.controller.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Req,
|
||||
UseGuards,
|
||||
} from "@nestjs/common";
|
||||
import { AuthGuard } from "../auth/guards/auth.guard";
|
||||
import type { AuthenticatedRequest } from "../common/interfaces/request.interface";
|
||||
import { CommentsService } from "./comments.service";
|
||||
import { CreateCommentDto } from "./dto/create-comment.dto";
|
||||
|
||||
@Controller()
|
||||
export class CommentsController {
|
||||
constructor(private readonly commentsService: CommentsService) {}
|
||||
|
||||
@Get("contents/:contentId/comments")
|
||||
findAllByContentId(@Param("contentId") contentId: string) {
|
||||
return this.commentsService.findAllByContentId(contentId);
|
||||
}
|
||||
|
||||
@Post("contents/:contentId/comments")
|
||||
@UseGuards(AuthGuard)
|
||||
create(
|
||||
@Req() req: AuthenticatedRequest,
|
||||
@Param("contentId") contentId: string,
|
||||
@Body() dto: CreateCommentDto,
|
||||
) {
|
||||
return this.commentsService.create(req.user.sub, contentId, dto);
|
||||
}
|
||||
|
||||
@Delete("comments/:id")
|
||||
@UseGuards(AuthGuard)
|
||||
remove(@Req() req: AuthenticatedRequest, @Param("id") id: string) {
|
||||
const isAdmin = req.user.role === "admin" || req.user.role === "moderator";
|
||||
return this.commentsService.remove(req.user.sub, id, isAdmin);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user