-
Notifications
You must be signed in to change notification settings - Fork 0
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
[BE/#458] 신고하기 API 구현 #459
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c6128b
[BE] Feat : report 모듈 생성
koomin1227 a48d95a
[BE] Feat : report 생성 dto 생성
koomin1227 e4f4481
[BE] Feat : report entity 생성
koomin1227 9476823
[BE] Feat : report entity 등록
koomin1227 4ae1441
[BE] Feat : report 등록 controller 구현
koomin1227 d593178
[BE] Feat : report entity 변경
koomin1227 abd9c5e
[BE] Feat : report 등록 서비스 구현
koomin1227 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,39 @@ | ||
import { | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { UserEntity } from './user.entity'; | ||
import { PostEntity } from './post.entity'; | ||
|
||
@Entity('report') | ||
export class ReportEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ nullable: false, charset: 'utf8' }) | ||
user_hash: string; | ||
|
||
@Column({ nullable: false }) | ||
post_id: number; | ||
|
||
@Column({ charset: 'utf8' }) | ||
description: string; | ||
|
||
@Column({ nullable: false, charset: 'utf8' }) | ||
reporter: string; | ||
|
||
@ManyToOne(() => UserEntity, (user) => user.user_hash) | ||
@JoinColumn({ name: 'user_hash', referencedColumnName: 'user_hash' }) | ||
reportedUser: UserEntity; | ||
|
||
@ManyToOne(() => PostEntity, (post) => post.id) | ||
@JoinColumn({ name: 'post_id', referencedColumnName: 'id' }) | ||
post: PostEntity; | ||
|
||
@ManyToOne(() => UserEntity, (user) => user.user_hash) | ||
@JoinColumn({ name: 'reporter', referencedColumnName: 'user_hash' }) | ||
reportingUser: UserEntity; | ||
} |
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,12 @@ | ||
import { IsNumber, IsString } from 'class-validator'; | ||
|
||
export class CreateReportDto { | ||
@IsString() | ||
description: string; | ||
|
||
@IsNumber() | ||
post_id: number; | ||
|
||
@IsString() | ||
user_id: string; | ||
} |
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,18 @@ | ||
import { Body, Controller, Post, UseGuards } from '@nestjs/common'; | ||
import { CreateReportDto } from './createReport.dto'; | ||
import { ReportService } from './report.service'; | ||
import { AuthGuard } from '../utils/auth.guard'; | ||
import { UserHash } from '../utils/auth.decorator'; | ||
|
||
@Controller('report') | ||
@UseGuards(AuthGuard) | ||
export class ReportController { | ||
constructor(private readonly reportService: ReportService) {} | ||
@Post() | ||
async createReport( | ||
@Body() body: CreateReportDto, | ||
@UserHash() userId: string, | ||
) { | ||
await this.reportService.createReport(body, userId); | ||
} | ||
} |
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,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ReportController } from './report.controller'; | ||
import { ReportService } from './report.service'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { ReportEntity } from '../entities/report.entity'; | ||
import { PostEntity } from '../entities/post.entity'; | ||
import { UserEntity } from '../entities/user.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([ReportEntity, PostEntity, UserEntity])], | ||
controllers: [ReportController], | ||
providers: [ReportService], | ||
}) | ||
export class ReportModule {} |
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,43 @@ | ||
import { HttpException, Injectable } from '@nestjs/common'; | ||
import { CreateReportDto } from './createReport.dto'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { ReportEntity } from '../entities/report.entity'; | ||
import { PostEntity } from '../entities/post.entity'; | ||
import { UserEntity } from '../entities/user.entity'; | ||
|
||
@Injectable() | ||
export class ReportService { | ||
constructor( | ||
@InjectRepository(ReportEntity) | ||
private reportRepository: Repository<ReportEntity>, | ||
@InjectRepository(PostEntity) | ||
private postRepository: Repository<PostEntity>, | ||
@InjectRepository(UserEntity) | ||
private userRepository: Repository<UserEntity>, | ||
) {} | ||
async createReport(body: CreateReportDto, userId: string) { | ||
const isAllExist = await this.isExist(body.post_id, body.user_id); | ||
if (body.user_id === userId) { | ||
throw new HttpException('자신의 게시글은 신고 할 수 없습니다.', 400); | ||
} | ||
if (!isAllExist) { | ||
throw new HttpException('신고할 대상이 존재 하지 않습니다.', 404); | ||
} | ||
const reportEntity = new ReportEntity(); | ||
reportEntity.post_id = body.post_id; | ||
reportEntity.user_hash = body.user_id; | ||
reportEntity.description = body.description; | ||
reportEntity.reporter = userId; | ||
await this.reportRepository.save(reportEntity); | ||
} | ||
async isExist(postId, userId) { | ||
const isPostExist: boolean = await this.postRepository.exist({ | ||
where: { id: postId }, | ||
}); | ||
const isUserExist: boolean = await this.userRepository.exist({ | ||
where: { user_hash: userId }, | ||
}); | ||
return !!(isPostExist && isUserExist); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼼꼼한 오류처리 좋습니다~