import { Controller, Get, Post, Put, Delete, Body, Param, Query, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { ContentsService } from './contents.service';

@ApiTags('内容')
@Controller('contents')
export class ContentsController {
  constructor(private contentsService: ContentsService) {}

  @Get()
  async findAll(@Query() query: { page?: number; pageSize?: number; categoryId?: number; contentType?: string }) {
    return this.contentsService.findAll(query);
  }

  @Get(':id')
  async findById(@Param('id') id: string) {
    return this.contentsService.findById(+id);
  }

  @Post()
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async create(@Body() body: any) {
    return this.contentsService.create(body);
  }

  @Put(':id')
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async update(@Param('id') id: string, @Body() body: any) {
    return this.contentsService.update(+id, body);
  }

  @Delete(':id')
  @UseGuards(AuthGuard('jwt'))
  @ApiBearerAuth()
  async remove(@Param('id') id: string) {
    return this.contentsService.remove(+id);
  }
}
