import { Body, Controller, Del, Get, Inject, Param, Post, Query, } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { StudioService } from '../service/studio.service'; import { CDTO_studio, CVO_studio, FVO_studio, QDTO_studio, QVO_studio, UDTO_studio, UVAO_studio, } from '../interface/studio.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['工作室']) @Controller('/studio') export class StudioController extends BaseController { @Inject() service: StudioService; @Post('/') @Validate() @ApiResponse({ type: CVO_studio }) async create(@Body() data: CDTO_studio) { const dbData = await this.service.create(data); const result = new CVO_studio(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_studio }) async query( @Query() filter: QDTO_studio, @Query('skip') skip: number, @Query('limit') limit: number ) { const list = await this.service.query(filter, { skip, limit }); const data = []; for (const i of list) { const newData = new QVO_studio(i); data.push(newData); } const total = await this.service.count(filter); return { data, total }; } @Get('/:id') @ApiResponse({ type: FVO_studio }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_studio(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_studio }) async update(@Param('id') id: string, @Body() body: UDTO_studio) { const result = await this.service.update(id, body); return result; } @Del('/:id') @Validate() async delete(@Param('id') id: string) { await this.service.delete(id); return 'ok'; } async createMany(...args: any[]) { throw new Error('Method not implemented.'); } async updateMany(...args: any[]) { throw new Error('Method not implemented.'); } async deleteMany(...args: any[]) { throw new Error('Method not implemented.'); } }