From f1b7fb708dd85eaea3cc78a9ee0797d5ed9f732a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Wed, 22 Nov 2023 00:03:00 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20Feat=20:=20DeletePost=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/post/post.controller.ts | 14 +++++++++++++- BE/src/post/post.service.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/BE/src/post/post.controller.ts b/BE/src/post/post.controller.ts index 7842e72..a1027d9 100644 --- a/BE/src/post/post.controller.ts +++ b/BE/src/post/post.controller.ts @@ -8,10 +8,11 @@ import { Patch, Req, Res, - Post, + Post, UploadedFiles, UseInterceptors, ValidationPipe, + Delete, } from '@nestjs/common'; import { PostService } from './post.service'; import { ApiOperation, ApiTags } from '@nestjs/swagger'; @@ -76,4 +77,15 @@ export class PostController { throw new HttpException('서버 오류입니다.', 500); } } + + @Delete('/:id') + async postRemove(@Param('id') id: number) { + const isRemoved = await this.postService.deletePostById(id); + + if (isRemoved) { + return HttpCode(200); + } else { + throw new HttpException('게시글이 존재하지 않습니다.', 404); + } + } } diff --git a/BE/src/post/post.service.ts b/BE/src/post/post.service.ts index c42aac5..e19016b 100644 --- a/BE/src/post/post.service.ts +++ b/BE/src/post/post.service.ts @@ -140,4 +140,17 @@ export class PostService { await this.postImageRepository.save(postImageEntity); } } + + async deletePostById(postId: number) { + const isDataExists = await this.postRepository.findOne({ + where: { id: postId, status: true }, + }); + + if (!isDataExists) { + return false; + } else { + await this.postRepository.update({ id: postId }, { status: false }); + return true; + } + } }