Skip to content

Commit

Permalink
feat: create restore content api
Browse files Browse the repository at this point in the history
  • Loading branch information
stae1102 committed Jun 9, 2024
1 parent 084857e commit 3a733bf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/contents/contents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,19 @@ export class ContentsController {
return this.contentsService.summarizeContent(user, contentId);
}

// @ApiOperation({
// summary: '간편 문서 요약',
// description: '성능 테스트를 위해 만든 간편 문서 요약 메서드',
// })
// @ApiOkResponse({
// description: '간편 문서 요약 성공 여부를 반환한다.',
// type: SummarizeContentOutput,
// })
// @ApiBadRequestResponse({
// description: 'naver 서버에 잘못된 요청을 보냈을 경우',
// })
// @Post('summarize')
// async testSummarizeContent(
// @Body() content: SummarizeContentBodyDto,
// ): Promise<SummarizeContentOutput> {
// return this.contentsService.testSummarizeContent(content);
// }
@ApiOperation({
summary: '삭제된 컨텐츠 복원',
description: '삭제된 컨텐츠를 복원합니다.',
})
@ApiOkResponse({
description: '삭제된 컨텐츠 복원 성공 여부를 반환합니다.',
})
@UseGuards(JwtAuthGuard)
@Patch(':contentId/restore')
async restoreContent(
@AuthUser() user: User,
@Param('contentId', new ParseIntPipe()) contentId: number,
) {
return this.contentsService.restoreContent(user, contentId);
}
}
27 changes: 27 additions & 0 deletions src/contents/contents.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,31 @@ export class ContentsService {
throw e;
}
}

async restoreContent(user: User, contentId: number) {
try {
const content = await this.contentRepository.findOne({
where: {
id: contentId,
},
withDeleted: true,
});

if (!content) {
throw new NotFoundException('Content not found.');
}
if (content.userId !== user.id) {
throw new ForbiddenException(
'You are not allowed to restore this content',
);
}

content.deletedAt = null;
await this.contentRepository.save(content);

return {};
} catch (e) {
throw e;
}
}
}

0 comments on commit 3a733bf

Please sign in to comment.