import { JwtGuard } from '@/common/guards';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ArticleService } from './article.service';
import { CreateArticleDto, GetArticleDto, QueryArticleDto, UpdateArticleDto } from './dto';

@Controller('article')
@ApiTags('article')
@ApiBearerAuth('JWT')
@UseGuards(JwtGuard)
export class ArticleController {
  constructor(private readonly articleService: ArticleService) {}

  @Post()
  create(@Body() createArticleDto: CreateArticleDto) {
    return this.articleService.create(createArticleDto);
  }

  @Get()
  getAll(@Param() getArticleDto: GetArticleDto) {
    return this.articleService.findAll(getArticleDto);
  }
  @Get('detail/:id')
  getArticle(@Param('id') id: string) {
    return this.articleService.find(+id);
  }
  @Get('page')
  findPagination(@Query() queryDto: QueryArticleDto) {
    return this.articleService.findPagination(queryDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.articleService.remove(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateCategoryDto: UpdateArticleDto) {
    return this.articleService.update(+id, updateCategoryDto);
  }

  @Post('up/:id')
  up(@Param('id') id: string,) {
    return this.articleService.up(+id);
  }

  @Post('down/:id')
  down(@Param('id') id: string,) {
    return this.articleService.down(+id);
  }
}
