Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/bounswe/bounswe2023g…
Browse files Browse the repository at this point in the history
…roup7 into feature/BE/474/follow-info-for-game-list
  • Loading branch information
omersafakbebek committed Nov 21, 2023
2 parents a44644b + f746f6b commit 7166b25
Show file tree
Hide file tree
Showing 44 changed files with 2,495 additions and 412 deletions.
23 changes: 22 additions & 1 deletion ludos/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ import { GameController } from './controllers/game.controller';
import { GameService } from './services/game.service';
import { GameRepository } from './repositories/game.repository';
import { Game } from './entities/game.entity';
import { Comment } from './entities/comment.entity';
import { TokenDecoderMiddleware } from './middlewares/tokenDecoder.middleware';
import { ResetPasswordRepository } from './repositories/reset-password.repository';
import { CommentRepository } from './repositories/comment.repository';
import { S3Service } from './services/s3.service';
import { S3Controller } from './controllers/s3.controller';
import { CommentService } from './services/comment.service';
import { CommentController } from './controllers/comment.controller';
import { ReviewRepository } from './repositories/review.repository';
import { ReviewService } from './services/review.service';
import { ReviewController } from './controllers/review.controller';
import { Review } from './entities/review.entity';
import { RatingController } from './controllers/rating.controller';
import { RatingRepository } from './repositories/rating.repository';
import { RatingService } from './services/rating.service';
import { Rating } from './entities/rating.entity';

@Module({
imports: [
Expand All @@ -37,14 +45,23 @@ import { Review } from './entities/review.entity';
useClass: TypeOrmConfigService,
inject: [TypeOrmConfigService],
}),
TypeOrmModule.forFeature([User, Game, Review, ResetPassword]),
TypeOrmModule.forFeature([
User,
Game,
Review,
ResetPassword,
Rating,
Comment,
]),
],
controllers: [
AppController,
UserController,
GameController,
S3Controller,
ReviewController,
RatingController,
CommentController,
],
providers: [
AppService,
Expand All @@ -54,8 +71,12 @@ import { Review } from './entities/review.entity';
GameService,
ResetPasswordRepository,
S3Service,
CommentRepository,
CommentService,
ReviewRepository,
ReviewService,
RatingRepository,
RatingService,
],
})
export class AppModule implements NestModule {
Expand Down
183 changes: 183 additions & 0 deletions ludos/backend/src/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import {
Body,
Controller,
HttpCode,
Get,
Post,
Put,
Delete,
Req,
UseGuards,
Param,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiOkResponse,
ApiOperation,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { WriteCommentDto } from '../dtos/comment/request/write-comment.dto';
import { EditCommentDto } from '../dtos/comment/request/edit-comment.dto';
import { GetCommentResponseDto } from '../dtos/comment/response/get-comment.response.dto';
import { CommentService } from '../services/comment.service';
import { AuthGuard } from '../services/guards/auth.guard';
import { AuthorizedRequest } from '../interfaces/common/authorized-request.interface';

@ApiTags('comment')
@Controller('comment')
export class CommentController {
constructor(private readonly commentService: CommentService) {}

@ApiOperation({ summary: 'Get comment details' })
@ApiOkResponse({
description: 'Comment details',
type: GetCommentResponseDto,
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Get(':commentId/info')
public async getComment(
@Req() req: AuthorizedRequest,
@Param('commentId') commentId: string,
) {
return await this.commentService.getComment(req.user.id, commentId);
}

@ApiOperation({ summary: 'Get comments of post/comment/review' })
@ApiOkResponse({
description: 'Comments of post/comment/review',
type: [GetCommentResponseDto],
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Get(':parentId')
public async getCommentDetails(
@Req() req: AuthorizedRequest,
@Param('parentId') parentId: string,
) {
return await this.commentService.getCommentsByParent(req.user.id, parentId);
}

@ApiOperation({ summary: 'Comment on a post/comment/review' })
@ApiOkResponse({
description: 'Comment',
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Post('/write-comment')
public async writeComment(
@Req() req: AuthorizedRequest,
@Body() input: WriteCommentDto,
) {
await this.commentService.writeComment(req.user.id, input);
}

@ApiOperation({ summary: 'Like a comment' })
@ApiOkResponse({
description: 'Like Comment',
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Post(':commentId/like-comment')
public async likeComment(
@Req() req: AuthorizedRequest,
@Param('commentId') commentId: string,
) {
await this.commentService.likeComment(req.user.id, commentId);
}

@ApiOperation({ summary: 'Dislike a comment' })
@ApiOkResponse({
description: 'Dislike Comment',
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Post(':commentId/dislike-comment')
public async dislikeComment(
@Req() req: AuthorizedRequest,
@Param('commentId') commentId: string,
) {
await this.commentService.dislikeComment(req.user.id, commentId);
}

@ApiOperation({ summary: 'Delete a comment' })
@ApiOkResponse({
description: 'Deleted Comment',
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Delete(':commentId/delete-comment')
public async deleteComment(
@Req() req: AuthorizedRequest,
@Param('commentId') commentId: string,
) {
console.log('comment id: ', commentId);
await this.commentService.deleteComment(req.user.id, commentId);
}

@ApiOperation({ summary: 'Edit a comment' })
@ApiOkResponse({
description: 'Edited Comment',
})
@ApiUnauthorizedResponse({
description: 'Invalid Credentials',
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(200)
@ApiBearerAuth()
@UseGuards(AuthGuard)
@Put(':commentId/edit-comment')
public async editComment(
@Req() req: AuthorizedRequest,
@Param('commentId') commentId: string,
@Body() input: EditCommentDto,
) {
await this.commentService.editComment(req.user.id, commentId, input);
}
}
87 changes: 87 additions & 0 deletions ludos/backend/src/controllers/rating.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import {
Body,
Controller,
HttpCode,
Delete,
Param,
Post,
Put,
Req,
UseGuards,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiBearerAuth,
ApiCreatedResponse,
ApiNotFoundResponse,
ApiTags,
} from '@nestjs/swagger';
import { RatingCreateDto } from '../dtos/rating/request/create.dto';
import { Rating } from '../entities/rating.entity';
import { AuthGuard } from '../services/guards/auth.guard';
import { AuthorizedRequest } from '../interfaces/common/authorized-request.interface';
import { RatingService } from '../services/rating.service';
import { RatingEditDto } from '../dtos/rating/request/edit.dto';

@UseGuards(AuthGuard)
@ApiTags('rating')
@Controller('rating')
export class RatingController {
constructor(private readonly ratingService: RatingService) {}

@ApiBearerAuth()
@ApiCreatedResponse({
description: 'Rating created successfully.',
type: Rating,
})
@ApiBadRequestResponse({
description: 'Bad Request',
})
@HttpCode(201)
@Post(':gameId')
public async createRating(
@Req() req: AuthorizedRequest,
@Param('gameId') gameId: string,
@Body() ratingCreateDto: RatingCreateDto,
) {
const createdRating = await this.ratingService.createRating(
req.user.id,
gameId,
ratingCreateDto,
);
return createdRating;
}

@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiNotFoundResponse({ description: 'Rating is not found!' })
@HttpCode(204)
@Delete(':gameId')
public async deleteRating(
@Req() req: AuthorizedRequest,
@Param('gameId') gameId: string,
) {
const deletedRatingResponse = await this.ratingService.deleteRating(
req.user.id,
gameId,
);
return deletedRatingResponse;
}

@UseGuards(AuthGuard)
@ApiBearerAuth()
@HttpCode(200)
@Put(':gameId')
public async editRating(
@Req() req: AuthorizedRequest,
@Param('gameId') gameId: string,
@Body() ratingEditDto: RatingEditDto,
) {
const editedRating = await this.ratingService.editRating(
req.user.id,
gameId,
ratingEditDto,
);
return editedRating;
}
}
7 changes: 7 additions & 0 deletions ludos/backend/src/dtos/comment/request/edit-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
export class EditCommentDto {
@ApiProperty()
@IsString()
newText: string;
}
11 changes: 11 additions & 0 deletions ludos/backend/src/dtos/comment/request/write-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';
export class WriteCommentDto {
@ApiProperty()
@IsString()
parentId: string;

@ApiProperty()
@IsString()
text: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../../entities/user.entity';
import { IsDate, IsBoolean, IsString, IsNumber } from 'class-validator';

export class GetCommentResponseDto {
@ApiProperty({ type: () => User })
author: User;

@ApiProperty()
@IsDate()
timestamp: Date;

@ApiProperty()
@IsString()
text: string;

@ApiProperty()
@IsString()
parentId: string;

@ApiProperty()
@IsBoolean()
edited: boolean;

@ApiProperty()
@IsNumber()
likeCount: number;

@ApiProperty()
@IsNumber()
dislikeCount: number;
}
11 changes: 11 additions & 0 deletions ludos/backend/src/dtos/rating/request/create.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsNumber, Min, Max } from 'class-validator';

export class RatingCreateDto {
@IsNotEmpty()
@IsNumber()
@Min(0.0)
@Max(5.0)
@ApiProperty()
rating: number;
}
Loading

0 comments on commit 7166b25

Please sign in to comment.