feat(GOV-009): 建立后端契约与健康检查
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user