import { BaseController } from '@/common/base';
import { Respond, RespondType } from '@/common/response';
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, ParseIntPipe } from '@nestjs/common';
import { ApiOkResponse, ApiTags } from '@nestjs/swagger';
import { Create{{upcaseName name}}Dto } from './dto/create-{{fileName name}}.dto';
import { Find{{upcaseName name}}Dto } from './dto/find-{{fileName name}}.dto';
import { Update{{upcaseName name}}Dto } from './dto/update-{{fileName name}}.dto';
import { {{upcaseName name}} } from './entities/{{fileName name}}.entity';
import { {{upcaseName name}}Service } from './{{fileName name}}.service';

@ApiTags('{{fileName name}}')
@Controller('{{lowcaseName name}}s')
export class {{upcaseName name}}Controller extends BaseController {
  constructor(private {{lowcaseName name}}Service: {{upcaseName name}}Service) {
    super();
  }

  @Post()
  @ApiOperation({ description: '新增{{cnName}}', operationId: 'add{{upcaseName name}}' })
  add{{upcaseName name}}(@Body() create{{upcaseName name}}Dto: Create{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.create(create{{upcaseName name}}Dto);
  }

  @Get()
  @Respond(RespondType.PAGINATION)
  @ApiOkResponse({ isArray: true, type: {{upcaseName name}} })
  @ApiOperation({ description: '查询{{cnName}}', operationId: 'get{{upcaseName name}}s' })
  get{{upcaseName name}}s(@Query() query: Find{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.findMany(query);
  }

  @Get(':id')
  @ApiOperation({ description: '获取{{cnName}}', operationId: 'get{{upcaseName name}}' })
  get{{upcaseName name}}(id: number): Promise<{{upcaseName name}}> {
    return this.{{lowcaseName name}}Service.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ description: '更新{{cnName}}', operationId: 'set{{upcaseName name}}' })
  update{{upcaseName name}}(id: number, @Body() update{{upcaseName name}}Dto: Update{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.update(+id, update{{upcaseName name}}Dto);
  }

  @Delete(':id')
  @ApiOperation({ description: '删除{{cnName}}', operationId: 'del{{upcaseName name}}' })
  del{{upcaseName name}}(id: number) {
    return this.{{lowcaseName name}}Service.remove(+id);
  }
}
