90 lines
2.5 KiB
TypeScript
90 lines
2.5 KiB
TypeScript
|
|
import {
|
|||
|
|
Controller,
|
|||
|
|
Get,
|
|||
|
|
Post,
|
|||
|
|
Put,
|
|||
|
|
Delete,
|
|||
|
|
Body,
|
|||
|
|
Param,
|
|||
|
|
Query,
|
|||
|
|
UseGuards,
|
|||
|
|
UseInterceptors,
|
|||
|
|
UploadedFile,
|
|||
|
|
UploadedFiles,
|
|||
|
|
Session,
|
|||
|
|
Req,
|
|||
|
|
} from '@nestjs/common';
|
|||
|
|
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
|||
|
|
import {
|
|||
|
|
ApiTags,
|
|||
|
|
ApiOperation,
|
|||
|
|
ApiResponse,
|
|||
|
|
ApiConsumes,
|
|||
|
|
} from '@nestjs/swagger';
|
|||
|
|
import { Request } from 'express';
|
|||
|
|
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
|
|||
|
|
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
|
|||
|
|
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
|
|||
|
|
import { Public } from '@wwjCommon/security/decorators/public.decorator';
|
|||
|
|
import { BusinessException } from '@wwjCommon/exception/business.exception';
|
|||
|
|
// @UploadedFile() - 单文件上传,配合 @UseInterceptors(FileInterceptor('file'))
|
|||
|
|
// @UploadedFiles() - 多文件上传,配合 @UseInterceptors(FilesInterceptor('files'))
|
|||
|
|
// @Session() - 获取会话对象,对应PHP Session::get()
|
|||
|
|
// @Req() - 获取Request对象,对应PHP Request
|
|||
|
|
import { PcService } from '../../services/admin/pc.service';
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* PcController
|
|||
|
|
* 对应 PHP: Pc Controller
|
|||
|
|
* 对应 Java: @RestController
|
|||
|
|
*
|
|||
|
|
* 支持装饰器:
|
|||
|
|
* - @UploadedFile() - 单文件上传 (对应PHP Request::file())
|
|||
|
|
* - @UploadedFiles() - 多文件上传
|
|||
|
|
* - @Session() - 会话管理 (对应PHP Session::get())
|
|||
|
|
* - @Req() - 请求对象 (对应PHP Request)
|
|||
|
|
*/
|
|||
|
|
@ApiTags('channel')
|
|||
|
|
@Controller('adminapi/channel')
|
|||
|
|
export class PcController {
|
|||
|
|
constructor(private readonly pcService: PcService) {}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* PC端配置
|
|||
|
|
* 路由: GET pc/config
|
|||
|
|
* PHP路由: Route::get('pc/config', 'channel.Pc/get')
|
|||
|
|
*/
|
|||
|
|
@Get('pc/config')
|
|||
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|||
|
|
@ApiOperation({ summary: 'PC端配置' })
|
|||
|
|
async get(): Promise<ApiResponse> {
|
|||
|
|
try {
|
|||
|
|
// 基于PHP真实逻辑实现
|
|||
|
|
// PHP原始方法: get
|
|||
|
|
|
|||
|
|
return await this.pcService.getPc();
|
|||
|
|
} catch (error) {
|
|||
|
|
throw new BusinessException('get操作失败', error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* PC端配置
|
|||
|
|
* 路由: PUT pc/config
|
|||
|
|
* PHP路由: Route::put('pc/config', 'channel.Pc/set')
|
|||
|
|
*/
|
|||
|
|
@Put('pc/config')
|
|||
|
|
@UseGuards(JwtAuthGuard, RolesGuard)
|
|||
|
|
@ApiOperation({ summary: 'PC端配置' })
|
|||
|
|
async set(@Body() data: SetDto): Promise<ApiResponse> {
|
|||
|
|
try {
|
|||
|
|
// 基于PHP真实逻辑实现
|
|||
|
|
// PHP原始方法: set
|
|||
|
|
|
|||
|
|
return await this.pcService.setPc(data);
|
|||
|
|
} catch (error) {
|
|||
|
|
throw new BusinessException('set操作失败', error);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|