-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of https://github.com/bounswe/bounswe2023g…
…roup7 into feature/BE/474/follow-info-for-game-list
- Loading branch information
Showing
44 changed files
with
2,495 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
ludos/backend/src/dtos/comment/request/write-comment.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
32 changes: 32 additions & 0 deletions
32
ludos/backend/src/dtos/comment/response/get-comment.response.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
Oops, something went wrong.