| 1 | import { Body, Controller, Get, Post, Put } from '@nestjs/common' |
| 2 | import { ApiTags } from '@nestjs/swagger' |
| 3 | import { ApiDoc } from '@yikart/common' |
| 4 | import { ConfigEditorConfigDto } from './config-editor.dto' |
| 5 | import { ConfigEditorService } from './config-editor.service' |
| 6 | import { ConfigEditorConfigVo } from './config-editor.vo' |
| 7 | import { ConfigRestartService } from './config-restart.service' |
| 8 | |
| 9 | @ApiTags('ConfigEditor') |
| 10 | @Controller() |
| 11 | export class ConfigEditorController { |
| 12 | constructor( |
| 13 | private readonly configEditorService: ConfigEditorService, |
| 14 | private readonly configRestartService: ConfigRestartService, |
| 15 | ) {} |
| 16 | |
| 17 | @ApiDoc({ |
| 18 | summary: '获取配置文件', |
| 19 | response: ConfigEditorConfigVo, |
| 20 | }) |
| 21 | @Get() |
| 22 | async getConfig(): Promise<ConfigEditorConfigVo> { |
| 23 | return ConfigEditorConfigVo.create(await this.configEditorService.getConfig()) |
| 24 | } |
| 25 | |
| 26 | @ApiDoc({ |
| 27 | summary: '校验配置文件内容', |
| 28 | body: ConfigEditorConfigDto.schema, |
| 29 | }) |
| 30 | @Post('validate') |
| 31 | validateConfig(@Body() body: ConfigEditorConfigDto): void { |
| 32 | this.configEditorService.validateConfig(body.config) |
| 33 | } |
| 34 | |
| 35 | @ApiDoc({ |
| 36 | summary: '保存配置文件内容', |
| 37 | body: ConfigEditorConfigDto.schema, |
| 38 | }) |
| 39 | @Put() |
| 40 | async saveConfig(@Body() body: ConfigEditorConfigDto): Promise<void> { |
| 41 | await this.configEditorService.saveConfig(body.config) |
| 42 | } |
| 43 | |
| 44 | @ApiDoc({ |
| 45 | summary: '重启当前服务', |
| 46 | }) |
| 47 | @Post('restart') |
| 48 | restart(): void { |
| 49 | this.configRestartService.restart() |
| 50 | } |
| 51 | } |
| 52 |