68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Body,
|
|
Param,
|
|
Query,
|
|
UseGuards,
|
|
Request,
|
|
} from '@nestjs/common';
|
|
import { Prisma } from '@prisma/client';
|
|
import { BlogsService } from './blogs.service';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
import {
|
|
ApiTags,
|
|
ApiBearerAuth,
|
|
ApiOperation,
|
|
ApiQuery,
|
|
} from '@nestjs/swagger';
|
|
|
|
import { PaginationDto } from '../common/dto/pagination.dto';
|
|
|
|
@ApiTags('Admin - مدیریت مقالات (بلاگ)')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('admin/blogs')
|
|
export class BlogsController {
|
|
constructor(private readonly blogsService: BlogsService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'لیست مقالات' })
|
|
@ApiQuery({ name: 'page', required: false, description: 'شماره صفحه' })
|
|
@ApiQuery({ name: 'limit', required: false, description: 'تعداد آیتمها' })
|
|
@ApiQuery({ name: 'search', required: false, description: 'جستجو' })
|
|
async getBlogs(@Query() query: PaginationDto) {
|
|
return this.blogsService.getBlogs(query);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: 'ایجاد مقاله جدید' })
|
|
async createBlog(
|
|
@Body() body: Prisma.BlogCreateWithoutAuthorInput,
|
|
@Request() req: { user: { id: string } },
|
|
) {
|
|
const data = await this.blogsService.createBlog(body, req.user.id);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Put(':id')
|
|
@ApiOperation({ summary: 'ویرایش مقاله' })
|
|
async updateBlog(
|
|
@Param('id') id: string,
|
|
@Body() body: Prisma.BlogUpdateInput,
|
|
) {
|
|
const data = await this.blogsService.updateBlog(id, body);
|
|
return { success: true, data };
|
|
}
|
|
|
|
@Delete(':id')
|
|
@ApiOperation({ summary: 'حذف مقاله' })
|
|
async deleteBlog(@Param('id') id: string) {
|
|
await this.blogsService.deleteBlog(id);
|
|
return { success: true };
|
|
}
|
|
}
|