import { Body, Controller, Post, HttpStatus, HttpCode, Get, Put, Query, Patch, Param, UseGuards, } from '@nestjs/common'; import { ApiTags, ApiOkResponse, ApiBody, ApiOperation, ApiBearerAuth, } from '@nestjs/swagger'; import { BlogCatDto, CreateBlogCatDto, UpdateBlogCatDto, StatusBlogCatDto, BlogCatListDto, getParentListBlogCatDto, } from '../../..//DTO/blogCategory.dto'; import { PostDto, CreatePostDto, UpdatePostDto, PostStatusDto, ListPostDto, FilterListPostDto, ChangeSortPostDto, } from '../../../DTO/blogPost.dto'; // import { DeletePostMediaDto } from '../../../DTO/postMedia.dto'; import { StatusPostCommentDto, ListPostCommentDto, PostCommentDto, CreatePostCommentDto, FilterListPostCommentDto, PostCommentInfoDto, } from '../../../DTO/blogPostComment.dto'; import { BlogService } from './blog.service'; import { Roles } from '../../../decorators/role.decorators'; import { Role } from '../../../common/eNums/role.enum'; import { AuthGuard } from '../../../auth/auth.guard'; import { CurrentUser } from '../../../decorators/currentUser.decorator'; @ApiTags('admin blog') @Controller('admins/blog') export class BlogController { constructor(private readonly blogService: BlogService) {} // create new post ************************************************************************** @ApiOperation({ summary: ' ساخت پست برای بلاگ ' }) @ApiOkResponse({ description: 'PostDto info', type: [PostDto], }) @ApiBody({ type: CreatePostDto, description: 'create new post', }) @Post('post') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async createPost( @CurrentUser() user, @Body() createPostDto: CreatePostDto, ): Promise { try { await this.blogService.createPost(createPostDto, user); return true; } catch (err) { throw err; } } // update post ****************************************************************************** @HttpCode(HttpStatus.OK) @ApiOperation({ summary: ' بروز رسانی پست ' }) @ApiOkResponse({ description: 'update post', type: Boolean, }) @ApiBody({ type: UpdatePostDto, description: 'update post DTO', }) @Put('post') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async updatePost( @CurrentUser() user, @Body() updatePostDto: UpdatePostDto, ): Promise { try { await this.blogService.updatePost(updatePostDto, user); return { status: true }; } catch (err) { throw err; } } // change status of post ******************************************************************** @ApiOperation({ summary: 'تغییر وضعیت پست بلاگ' }) @ApiOkResponse({ description: 'api status', type: Boolean, }) @ApiBody({ type: PostStatusDto, description: 'change Status of post', }) @Patch('post') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async changeStatusPost(@Body() postStatusDto: PostStatusDto): Promise { try { await this.blogService.changeStatusPost(postStatusDto); return { status: true }; } catch (err) { throw err; } } // Filter / list post *********************************************************************** @ApiOperation({ summary: ' فیلتر و لیست پست های بلاگ' }) @HttpCode(HttpStatus.OK) @ApiOkResponse({ description: 'posts list', type: [ListPostDto], }) @Get('post') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async ListPosts( @Query() filterListPostDto: FilterListPostDto, ): Promise { const blogService = await this.blogService.listPosts(filterListPostDto); return blogService; } // get detail post by id ***************************************************************************** @ApiOperation({ summary: 'جزییات کامل پست بلاگ' }) @ApiOkResponse({ description: 'post detail info', type: PostDto, }) @Get('post/:postId') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async postDetail( @Param('postId') postId: string, ): Promise { try { const postDetail = await this.blogService.postDetail(postId); return postDetail; } catch (err) { throw err; } } // change sort post ************************************************************************ @ApiOperation({ summary: 'تغییر ترتیب پست' }) @HttpCode(HttpStatus.OK) @ApiOkResponse({ description: 'change sort post', type: [ListPostDto], }) @ApiBody({ type: ChangeSortPostDto, description: 'change sort post', }) @Put('post/sort') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async changeSortPost( @Body() changeSortPostDto: ChangeSortPostDto, ): Promise { try { await this.blogService.changeSortPost(changeSortPostDto); return true; } catch (err) { throw err; } } // create new blogCat *********************************************************************** @ApiOperation({ summary: ' ساخت دسته بندی بلاگ ' }) @ApiOkResponse({ description: 'blog Category Dto info', type: [BlogCatDto], }) @ApiBody({ type: CreateBlogCatDto, description: 'create new blog category', }) @Post('category') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async createCategory( @Body() createBlogCatDto: CreateBlogCatDto, ): Promise { try { const category = await this.blogService.createCategory(createBlogCatDto); return category; } catch (err) { throw err; } } // list blogCat *********************************************************************** @ApiOperation({ summary: ' لیست دسته بندی های بلاگ ' }) @HttpCode(HttpStatus.OK) @ApiOkResponse({ description: 'blog category list', type: [BlogCatListDto], }) @Get('category') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async blogCatList( @Query() getParentForListDto: getParentListBlogCatDto, ): Promise { try { const categories = await this.blogService.blogCatList( getParentForListDto, ); return categories; } catch (err) { throw err; } } // update blogCat ********************************************************************** @ApiOperation({ summary: ' بروز رسانی دسته بندی بلاگ ' }) @HttpCode(HttpStatus.OK) @ApiOkResponse({ description: 'update blog category', type: Boolean, }) @ApiBody({ type: UpdateBlogCatDto, description: 'update blog category', }) @Put('category') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async updateBlogCategory( @Body() updateBlogCategory: UpdateBlogCatDto, ): Promise { try { await this.blogService.updateBlogCategory(updateBlogCategory); return { status: true }; } catch (err) { throw err; } } //change status of blog Category ********************************************************************** @ApiOperation({ summary: ' وضعیت دسته بندی بلاگ ' }) @ApiOkResponse({ description: 'api status', type: Boolean, }) @ApiBody({ type: StatusBlogCatDto, description: 'change Status of blog category', }) @Patch('category') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async changeStatusCategory( @Body() statusBlogCatDto: StatusBlogCatDto, ): Promise { try { await this.blogService.changeStatusCategory(statusBlogCatDto); return { status: true }; } catch (err) { throw err; } } // Filter/ list post comment ******************************************************************** @ApiOperation({ summary: ' لیست پست ها به همراه فیلتر ' }) @ApiOkResponse({ description: 'postComments List', type: [ListPostCommentDto], }) @HttpCode(HttpStatus.OK) @Get('postComment') @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async listPostComment( @Query() filterListPostCommentDto: FilterListPostCommentDto, ): Promise { const list = await this.blogService.listPostComments( filterListPostCommentDto, ); return list; } //get post comment detail by id **************************************************************** @ApiOperation({ summary: 'detail PostComment' }) @ApiOkResponse({ description: 'post comment detail info', type: PostCommentInfoDto, }) @HttpCode(HttpStatus.OK) @Get('postComment/:id') @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async postCommentDetail( @Param('id') id: string, ): Promise { try { const postCommentDetail = await this.blogService.postCommentDetail(id); return postCommentDetail; } catch (err) { throw err; } } // changeStatus postComment ********************************************************************* @ApiOperation({ summary: 'change status PostComment' }) @ApiOkResponse({ description: 'api status', type: Boolean, }) @ApiBody({ type: StatusPostCommentDto, description: 'change status of postComment', }) @Patch('postComment') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async changeStatusPostComment( @Body() statusPostCommentDto: StatusPostCommentDto, ): Promise { try { await this.blogService.changeStatusPostComment(statusPostCommentDto); return { status: true }; } catch (err) { throw err; } } // reply post comment ***************************************************** @ApiOperation({ summary: 'reply PostComment' }) @ApiOkResponse({ description: 'PostComment Dto', type: [PostCommentDto], }) @ApiBody({ type: CreatePostCommentDto, description: 'reply post comment', }) @Post('postComment/reply/:id') @HttpCode(HttpStatus.OK) @UseGuards(AuthGuard) @Roles(Role.Admin) @ApiBearerAuth() async replyPostComment( @CurrentUser() user, @Body() createPostCommentDto: CreatePostCommentDto, @Param('id') id: string, ): Promise { try { const result = await this.blogService.replyPostComment( createPostCommentDto, id, user, ); return result; } catch (err) { throw err; } } }