Skip to content

Commit

Permalink
Merge pull request #50 from DevKor-github/feature/community
Browse files Browse the repository at this point in the history
Feature/community
  • Loading branch information
KimSeongHyeonn authored Jul 24, 2024
2 parents 9726d91 + 0174b7a commit 518dc67
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { CommentModule } from './community/comment/comment.module';
import { NoticeModule } from './notice/notice.module';
import { CalendarModule } from './home/calendar/calendar.module';
import { InstitutionModule } from './home/institution/institution.module';
import { ReportModule } from './community/report/report.module';

console.log(`.env.${process.env.NODE_ENV}`);

Expand Down Expand Up @@ -64,6 +65,7 @@ console.log(`.env.${process.env.NODE_ENV}`);
NoticeModule,
CalendarModule,
InstitutionModule,
ReportModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
44 changes: 43 additions & 1 deletion src/community/comment/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@ import { GetCommentResponseDto } from './dto/get-comment.dto';
import { UpdateCommentRequestDto } from './dto/update-comment.dto';
import { DeleteCommentResponseDto } from './dto/delete-comment.dto';
import { LikeCommentResponseDto } from './dto/like-comment.dto';
import {
CreateReportRequestDto,
CreateReportResponseDto,
} from '../report/dto/create-report.dto';
import { ReportService } from '../report/report.service';

@Controller('comment')
@ApiTags('comment')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('accessToken')
export class CommentController {
constructor(private readonly commentService: CommentService) {}
constructor(
private readonly commentService: CommentService,
private readonly reportService: ReportService,
) {}

@Post()
@ApiOperation({
Expand Down Expand Up @@ -140,4 +148,38 @@ export class CommentController {
): Promise<LikeCommentResponseDto> {
return await this.commentService.likeComment(user, commentId);
}

@Post('/:commentId/report')
@ApiOperation({
summary: '댓글 신고',
description: '댓글을 신고합니다',
})
@ApiParam({
name: 'commentId',
description: '댓글의 고유 ID',
})
@ApiBody({
type: CreateReportRequestDto,
})
@ApiResponse({
status: 201,
description: '댓글 신고 성공',
type: CreateReportResponseDto,
})
async reportPost(
@User() user: AuthorizedUserDto,
@Param('commentId') commentId: number,
@Body() body: CreateReportRequestDto,
): Promise<CreateReportResponseDto> {
const comment = await this.commentService.getComment(commentId);
if (!comment) {
throw new BadRequestException('Wrong CommentId!');
}
return await this.reportService.createReport(
user.id,
body.reason,
comment.postId,
commentId,
);
}
}
2 changes: 2 additions & 0 deletions src/community/comment/comment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PostModule } from '../post/post.module';
import { CommentLikeEntity } from 'src/entities/comment-like.entity';
import { CommentAnonymousNumberEntity } from 'src/entities/comment-anonymous-number.entity';
import { NoticeModule } from 'src/notice/notice.module';
import { ReportModule } from '../report/report.module';

@Module({
imports: [
Expand All @@ -18,6 +19,7 @@ import { NoticeModule } from 'src/notice/notice.module';
]),
PostModule,
NoticeModule,
ReportModule,
],
controllers: [CommentController],
providers: [CommentService, CommentRepository],
Expand Down
4 changes: 4 additions & 0 deletions src/community/comment/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,8 @@ export class CommentService {
await queryRunner.release();
}
}

async getComment(commentId: number): Promise<CommentEntity> {
return await this.commentRepository.getCommentByCommentId(commentId);
}
}
38 changes: 37 additions & 1 deletion src/community/post/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ import {
ReactPostRequestDto,
ReactPostResponseDto,
} from './dto/react-post.dto';
import {
CreateReportRequestDto,
CreateReportResponseDto,
} from '../report/dto/create-report.dto';
import { ReportService } from '../report/report.service';

@Controller('post')
@ApiTags('post')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('accessToken')
export class PostController {
constructor(private readonly postService: PostService) {}
constructor(
private readonly postService: PostService,
private readonly reportService: ReportService,
) {}

@Get()
@ApiOperation({
Expand Down Expand Up @@ -316,4 +324,32 @@ export class PostController {
): Promise<ReactPostResponseDto> {
return await this.postService.reactPost(user, postId, body);
}

@Post('/:postId/report')
@ApiOperation({
summary: '게시글 신고',
description: '게시글을 신고합니다',
})
@ApiParam({
name: 'postId',
description: '게시글의 고유 ID',
})
@ApiBody({
type: CreateReportRequestDto,
})
@ApiResponse({
status: 201,
description: '게시글 신고 성공',
type: CreateReportResponseDto,
})
async reportPost(
@User() user: AuthorizedUserDto,
@Param('postId') postId: number,
@Body() body: CreateReportRequestDto,
): Promise<CreateReportResponseDto> {
if (!(await this.postService.isExistingPostId(postId))) {
throw new BadRequestException('Wrong PostId!');
}
return await this.reportService.createReport(user.id, body.reason, postId);
}
}
2 changes: 2 additions & 0 deletions src/community/post/post.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { CommonModule } from 'src/common/common.module';
import { PostScrapRepository } from './post-scrap.repository';
import { PostScrapEntity } from 'src/entities/post-scrap.entity';
import { PostReactionEntity } from 'src/entities/post-reaction.entity';
import { ReportModule } from '../report/report.module';

@Module({
imports: [
Expand All @@ -22,6 +23,7 @@ import { PostReactionEntity } from 'src/entities/post-reaction.entity';
]),
BoardModule,
CommonModule,
ReportModule,
],
controllers: [PostController],
providers: [
Expand Down
17 changes: 17 additions & 0 deletions src/community/report/dto/create-report.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';

export class CreateReportRequestDto {
@IsNotEmpty()
@IsString()
@ApiProperty({ description: '신고 사유' })
reason: string;
}

export class CreateReportResponseDto {
constructor(isReported: boolean) {
this.isReported = isReported;
}
@ApiProperty({ description: '신고 처리 여부' })
isReported: boolean;
}
22 changes: 22 additions & 0 deletions src/community/report/dto/get-report-list.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiProperty } from '@nestjs/swagger';
import { ReportEntity } from 'src/entities/report.entity';

export class GetReportListResponseDto {
constructor(reportEntity: ReportEntity) {
this.id = reportEntity.id;
this.createdAt = reportEntity.createdAt;
this.reason = reportEntity.reason;
this.isPost = reportEntity.commentId ? false : true;
}
@ApiProperty({ description: '신고 고유 ID' })
id: number;

@ApiProperty({ description: '신고 일시' })
createdAt: Date;

@ApiProperty({ description: '신고 사유' })
reason: string;

@ApiProperty({ description: '게시글 신고인지 여부(false 이면 댓글 신고)' })
isPost: boolean;
}
73 changes: 73 additions & 0 deletions src/community/report/dto/get-report.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { ApiProperty } from '@nestjs/swagger';
import { CommentEntity } from 'src/entities/comment.entity';
import { PostEntity } from 'src/entities/post.entity';
import { ReportEntity } from 'src/entities/report.entity';
import { UserEntity } from 'src/entities/user.entity';

class ReportedUser {
constructor(userEntity: UserEntity) {
this.id = userEntity.id;
this.username = userEntity.username;
}
@ApiProperty({ description: '사용자 고유 ID' })
id: number;

@ApiProperty({ description: '사용자 username' })
username: string;
}

class ReportedPost {
constructor(postEntity: PostEntity) {
this.id = postEntity.id;
this.title = postEntity.title;
this.content = postEntity.content;
this.imgDirs = postEntity.postImages.map((postImage) => postImage.imgDir);
}
@ApiProperty({ description: '게시글 고유 ID' })
id: number;

@ApiProperty({ description: '게시글 제목' })
title: string;

@ApiProperty({ description: '게시글 내용' })
content: string;

@ApiProperty({ description: '게시글 첨부 이미지' })
imgDirs: string[];
}

class ReportedComment {
constructor(commentEntity: CommentEntity) {
this.id = commentEntity.id;
this.content = commentEntity.content;
}
@ApiProperty({ description: '댓글 고유 ID' })
id: number;

@ApiProperty({ description: '댓글 내용' })
content: string;
}

export class GetReportResponseDto {
constructor(reportEntity: ReportEntity, count: number) {
if (!reportEntity.commentId) {
this.reportedPost = new ReportedPost(reportEntity.post);
this.reportedUser = new ReportedUser(reportEntity.post.user);
} else {
this.reportedComment = new ReportedComment(reportEntity.comment);
this.reportedUser = new ReportedUser(reportEntity.comment.user);
}
this.reportCount = count;
}
@ApiProperty({ description: '신고된 게시글' })
reportedPost?: ReportedPost;

@ApiProperty({ description: '신고된 댓글' })
reportedComment?: ReportedComment;

@ApiProperty({ description: '해당 글에 접수된 신고 횟수' })
reportCount: number;

@ApiProperty({ description: '신고된 사용자' })
reportedUser: ReportedUser;
}
60 changes: 60 additions & 0 deletions src/community/report/report.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { Controller, Param, Post, UseGuards } from '@nestjs/common';
import { ReportService } from './report.service';
import { AdminAuthGuard } from 'src/auth/guards/admin-auth.guard';
import { GetReportListResponseDto } from './dto/get-report-list.dto';
import {
ApiBody,
ApiOperation,
ApiParam,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { AdminRequestDto } from 'src/auth/dto/admin-request.dto';
import { GetReportResponseDto } from './dto/get-report.dto';

@Controller('report')
@UseGuards(AdminAuthGuard)
@ApiTags('report')
export class ReportController {
constructor(private readonly reportService: ReportService) {}

@Post()
@ApiOperation({
summary: '신고 목록 조회',
description: '신고 목록을 조회합니다.',
})
@ApiBody({
type: AdminRequestDto,
})
@ApiResponse({
status: 201,
description: '신고 목록 조회 성공',
type: [GetReportListResponseDto],
})
async getReportList(): Promise<GetReportListResponseDto[]> {
return await this.reportService.getReportList();
}

@Post('/:reportId')
@ApiOperation({
summary: '신고 세부내용 조회',
description: '신고 세부내용을 조회합니다.',
})
@ApiBody({
type: AdminRequestDto,
})
@ApiParam({
name: 'reportId',
description: '신고 고유 ID',
})
@ApiResponse({
status: 201,
description: '신고 목록 조회 성공',
type: GetReportResponseDto,
})
async getReport(
@Param('reportId') reportId: number,
): Promise<GetReportResponseDto> {
return await this.reportService.getReport(reportId);
}
}
15 changes: 15 additions & 0 deletions src/community/report/report.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ReportEntity } from 'src/entities/report.entity';
import { ReportService } from './report.service';
import { ReportRepository } from './report.repository';
import { ReportController } from './report.controller';
import { CommonModule } from 'src/common/common.module';

@Module({
imports: [TypeOrmModule.forFeature([ReportEntity]), CommonModule],
controllers: [ReportController],
providers: [ReportService, ReportRepository],
exports: [ReportService],
})
export class ReportModule {}
Loading

0 comments on commit 518dc67

Please sign in to comment.