import { Body, Controller, Del, Get, Inject, Param, Post, Query } from '@midwayjs/decorator'; import { BaseController } from 'free-midway-component'; import { MenusService } from '../service/menus.service'; import { CDTO_menus, CVO_menus, FVO_menus, QDTO_menus, QVO_menus, UDTO_menus, UVAO_menus } from '../interface/menus.interface'; import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger'; import { Validate } from '@midwayjs/validate'; @ApiTags(['菜单']) @Controller('/menus') export class MenusController extends BaseController { @Inject() service: MenusService; @Post('/') @Validate() @ApiResponse({ type: CVO_menus }) async create(@Body() data: CDTO_menus) { const dbData = await this.service.create(data); const result = new CVO_menus(dbData); return result; } @Get('/') @ApiQuery({ name: 'query' }) @ApiResponse({ type: QVO_menus }) async query() { const data = await this.service.queryMenu(); return data; } @Get('/:id') @ApiResponse({ type: FVO_menus }) async fetch(@Param('id') id: string) { const data = await this.service.fetch(id); const result = new FVO_menus(data); return result; } @Post('/:id') @Validate() @ApiResponse({ type: UVAO_menus }) async update(@Param('id') id: string, @Body() body: UDTO_menus) { const result = await this.service.updateOne(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.'); } }