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();
  }

  /**
   * 新增{{cnName}}
   */
  @Post()
  add{{upcaseName name}}(@Body() create{{upcaseName name}}Dto: Create{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.create(create{{upcaseName name}}Dto);
  }

  /**
   * 根据分页/过滤参数查询{{cnName}}
   */
  @Get()
  @Respond(RespondType.PAGINATION)
  @ApiOkResponse({ isArray: true, type: {{upcaseName name}} })
  get{{upcaseName name}}s(@Query() query: Find{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.findMany(query);
  }

  /**
   * 根据ID查询{{cnName}}
   */
  @Get(':id')
  get{{upcaseName name}}(@Param('id', ParseIntPipe) id: number): Promise<{{upcaseName name}}> {
    return this.{{lowcaseName name}}Service.findOne(id);
  }

  /**
   * 根据ID更新{{cnName}}
   */
  @Patch(':id')
  update{{upcaseName name}}(@Param('id', ParseIntPipe) id: number, @Body() update{{upcaseName name}}Dto: Update{{upcaseName name}}Dto) {
    return this.{{lowcaseName name}}Service.update(+id, update{{upcaseName name}}Dto);
  }

  /**
   * 根据ID删除{{cnName}}
   */
  @Delete(':id')
  del{{upcaseName name}}(@Param('id', ParseIntPipe) id: number) {
    return this.{{lowcaseName name}}Service.remove(+id);
  }
}
