import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Patch,
} from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { TokenData } from 'src/common/decorator/token-data.decorator';
import { TokenDataEntity } from '../../common/entities/token-data.entity';
import { ResourceClassifyDto } from '../dto/resource-classify.dto';
import { ResourceClassifyService } from '../service/resource-classify.service';

@ApiTags('系统管理 - 组织机构')
@ApiBearerAuth()
@Controller('resource/classify')
export class ResourceClassifyController {
  constructor(
    private readonly resourceClassifyService: ResourceClassifyService,
  ) {}

  @Post()
  async create(
    @Body() resourceClassifyDto: ResourceClassifyDto,
    @TokenData() token: TokenDataEntity,
  ) {
    resourceClassifyDto.creator = resourceClassifyDto.updater = token.userId;
    return this.resourceClassifyService.create(resourceClassifyDto);
  }

  @Get()
  async findAll() {
    return this.resourceClassifyService.findAll();
  }

  @Patch(':id')
  async update(
    @Param('id') id: string,
    @Body() resourceClassifyDto: ResourceClassifyDto,
    @TokenData() token: TokenDataEntity,
  ) {
    resourceClassifyDto.updater = token.userId;
    return this.resourceClassifyService.update(+id, resourceClassifyDto);
  }

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