Skip to content

Commit

Permalink
Merge pull request #103 from boostcampwm2023/BE-deletePost-#102
Browse files Browse the repository at this point in the history
[BE/#102] Feat : DeletePost 구현
  • Loading branch information
koomin1227 authored Nov 21, 2023
2 parents c134a93 + f1b7fb7 commit efdf87d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion BE/src/post/post.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}
}
}
13 changes: 13 additions & 0 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit efdf87d

Please sign in to comment.