88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Param,
|
|
Body,
|
|
HttpStatus,
|
|
Query,
|
|
UseGuards,
|
|
Request,
|
|
} from '@nestjs/common';
|
|
import { BlogsService } from './blogs.service';
|
|
import {
|
|
ApiTags,
|
|
ApiOperation,
|
|
ApiResponse,
|
|
ApiOkResponse,
|
|
ApiNotFoundResponse,
|
|
ApiBearerAuth,
|
|
} from '@nestjs/swagger';
|
|
import { PaginationDto } from '../common/dto/pagination.dto';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
@ApiTags('Blogs - مجله سلامت')
|
|
@Controller('blogs')
|
|
@ApiResponse({
|
|
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
|
description: 'خطای داخلی سرور',
|
|
})
|
|
export class BlogsController {
|
|
constructor(private readonly blogsService: BlogsService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: 'دریافت لیست مقالات مجله سلامت' })
|
|
@ApiOkResponse({ description: 'لیست مقالات منتشر شده (صفحهبندی شده)' })
|
|
findAll(@Query() query: PaginationDto) {
|
|
return this.blogsService.findAll(query);
|
|
}
|
|
|
|
@Get('categories')
|
|
@ApiOperation({ summary: 'دریافت لیست دستهبندیهای وبلاگ' })
|
|
findCategories() {
|
|
return this.blogsService.getCategories();
|
|
}
|
|
|
|
@Get('tags')
|
|
@ApiOperation({ summary: 'دریافت لیست تگهای وبلاگ' })
|
|
findTags() {
|
|
return this.blogsService.getTags();
|
|
}
|
|
|
|
@Get('homepage')
|
|
@ApiOperation({ summary: 'دریافت مقالات برای نمایش در صفحه اصلی' })
|
|
@ApiOkResponse({ description: 'مقالات انتخاب شده برای صفحه اصلی' })
|
|
findHomepage() {
|
|
return this.blogsService.findHomepage();
|
|
}
|
|
|
|
@Get(':slug')
|
|
@ApiOperation({ summary: 'دریافت مقاله با اسلاگ (Slug)' })
|
|
@ApiOkResponse({ description: 'اطلاعات کامل مقاله' })
|
|
@ApiNotFoundResponse({ description: 'مقاله یافت نشد' })
|
|
findOne(@Param('slug') slug: string) {
|
|
return this.blogsService.findOneBySlug(slug);
|
|
}
|
|
|
|
@Get(':slug/comments')
|
|
@ApiOperation({ summary: 'دریافت نظرات تأیید شده مقاله' })
|
|
findComments(@Param('slug') slug: string) {
|
|
return this.blogsService.findCommentsBySlug(slug);
|
|
}
|
|
|
|
@UseGuards(JwtAuthGuard)
|
|
@ApiBearerAuth()
|
|
@Post(':slug/comments')
|
|
@ApiOperation({ summary: 'ارسال نظر برای مقاله (نیازمند ورود)' })
|
|
addComment(
|
|
@Param('slug') slug: string,
|
|
@Body() body: { userName: string; content: string },
|
|
@Request() req: any,
|
|
) {
|
|
return this.blogsService.addComment(slug, {
|
|
...body,
|
|
userId: req.user?.id,
|
|
});
|
|
}
|
|
}
|