This repository has been archived by the owner on May 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kaaang
committed
Feb 18, 2024
1 parent
d957410
commit 0627ed3
Showing
86 changed files
with
2,410 additions
and
1,990 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { AppService } from './app.service'; | ||
|
||
@Controller() | ||
export class AppController {} |
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 |
---|---|---|
@@ -1,79 +1,115 @@ | ||
import {Controller, Post, Body, Req, UseGuards, Param, Patch, Delete} from '@nestjs/common'; | ||
import { | ||
Controller, | ||
Post, | ||
Body, | ||
Req, | ||
UseGuards, | ||
Param, | ||
Patch, | ||
Delete, | ||
} from '@nestjs/common'; | ||
import { CommentService } from './comment.service'; | ||
import { CreateCommentDto } from './dto/create-comment.dto'; | ||
import { ResponseCode } from '../response/response-code.enum'; | ||
import { ResponseDto } from '../response/response.dto'; | ||
import { UserGuard } from '../user/user.guard'; | ||
import { Request } from 'express'; | ||
import {UserEntity} from "../user/user.entity"; | ||
import {RuleMainEntity} from "../rule/domain/rule.main.entity"; | ||
|
||
@Controller('mate/rule/detail/comment') | ||
export class CommentController { | ||
constructor( | ||
private readonly commentService: CommentService, | ||
) {} | ||
constructor(private readonly commentService: CommentService) {} | ||
|
||
// [1] 댓글 작성 | ||
@Post('/:ruleId') | ||
@UseGuards(UserGuard) | ||
async createComment(@Body() dto: CreateCommentDto, @Param('ruleId') ruleId: number, @Req() req: Request): Promise<ResponseDto<any>> { | ||
const result = await this.commentService.createComment(dto, ruleId, req.user.id); | ||
async createComment( | ||
@Body() dto: CreateCommentDto, | ||
@Param('ruleId') ruleId: number, | ||
@Req() req: Request, | ||
): Promise<ResponseDto<any>> { | ||
const result = await this.commentService.createComment( | ||
dto, | ||
ruleId, | ||
req.user.id, | ||
); | ||
|
||
console.log('controller 진입') | ||
if(!result){ | ||
console.log('controller 진입'); | ||
if (!result) { | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_CREATION_FAIL, | ||
false, | ||
"여행 규칙 코멘트 생성 실패", | ||
null); | ||
} | ||
else{ | ||
'여행 규칙 코멘트 생성 실패', | ||
null, | ||
); | ||
} else { | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_CREATED, | ||
true, | ||
"여행 규칙 코멘트 생성 성공", | ||
result); | ||
'여행 규칙 코멘트 생성 성공', | ||
result, | ||
); | ||
} | ||
} | ||
|
||
// [2] 댓글 수정 | ||
@Patch('/:ruleId/:commentId') | ||
@UseGuards(UserGuard) | ||
async updateComment(@Body() dto: CreateCommentDto, @Param('ruleId') ruleId: number, @Param('commentId') commentId: number,@Req() req: Request): Promise<ResponseDto<any>> { | ||
async updateComment( | ||
@Body() dto: CreateCommentDto, | ||
@Param('ruleId') ruleId: number, | ||
@Param('commentId') commentId: number, | ||
@Req() req: Request, | ||
): Promise<ResponseDto<any>> { | ||
try { | ||
const result = await this.commentService.updateComment(dto, ruleId, req.user.id, commentId); | ||
const result = await this.commentService.updateComment( | ||
dto, | ||
ruleId, | ||
req.user.id, | ||
commentId, | ||
); | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_UPDATE_SUCCESS, | ||
true, | ||
"여행 규칙 코멘트 수정 성공", | ||
result); | ||
ResponseCode.COMMENT_UPDATE_SUCCESS, | ||
true, | ||
'여행 규칙 코멘트 수정 성공', | ||
result, | ||
); | ||
} catch (e) { | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_UPDATE_FAIL, | ||
false, | ||
e.message, | ||
null); | ||
ResponseCode.COMMENT_UPDATE_FAIL, | ||
false, | ||
e.message, | ||
null, | ||
); | ||
} | ||
} | ||
|
||
// [3] 댓글 삭제 | ||
@Delete('/:ruleId/:commentId') | ||
@UseGuards(UserGuard) | ||
async deleteComment(@Param('ruleId') ruleId: number, @Param('commentId') commentId: number,@Req() req: Request): Promise<ResponseDto<any>> { | ||
async deleteComment( | ||
@Param('ruleId') ruleId: number, | ||
@Param('commentId') commentId: number, | ||
@Req() req: Request, | ||
): Promise<ResponseDto<any>> { | ||
try { | ||
const result = await this.commentService.deleteComment(ruleId, req.user.id, commentId); | ||
const result = await this.commentService.deleteComment( | ||
ruleId, | ||
req.user.id, | ||
commentId, | ||
); | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_DELETE_SUCCESS, | ||
true, | ||
"여행 규칙 코멘트 삭제 성공", | ||
result); | ||
ResponseCode.COMMENT_DELETE_SUCCESS, | ||
true, | ||
'여행 규칙 코멘트 삭제 성공', | ||
result, | ||
); | ||
} catch (e) { | ||
return new ResponseDto( | ||
ResponseCode.COMMENT_DELETE_FAIL, | ||
false, | ||
e.message, | ||
null); | ||
ResponseCode.COMMENT_DELETE_FAIL, | ||
false, | ||
e.message, | ||
null, | ||
); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class CreateCommentDto { | ||
@IsNotEmpty() | ||
@IsString() | ||
content: string; | ||
} | ||
@IsNotEmpty() | ||
@IsString() | ||
content: 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
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
Oops, something went wrong.