feat(GOV-009): 建立后端契约与健康检查

This commit is contained in:
2026-08-13 17:26:51 +08:00
parent 3fc703de0b
commit 420aa22342
32 changed files with 1625 additions and 8 deletions
+22
View File
@@ -0,0 +1,22 @@
import { Controller, Get, HttpException, HttpStatus, Inject } from '@nestjs/common';
import { ApiOkResponse, ApiServiceUnavailableResponse, ApiTags } from '@nestjs/swagger';
import { HealthResponseDto } from '../../../libs/http-contracts/src/health.dto';
import { HealthService } from './health.service';
@ApiTags('health')
@Controller('health')
export class HealthController {
constructor(@Inject(HealthService) private readonly healthService: HealthService) {}
@Get()
@ApiOkResponse({ type: HealthResponseDto })
@ApiServiceUnavailableResponse({ type: HealthResponseDto })
async getHealth(): Promise<HealthResponseDto> {
const response = await this.healthService.check();
if (response.status === 'unavailable') {
throw new HttpException(response, HttpStatus.SERVICE_UNAVAILABLE);
}
return response;
}
}