Files
wwjcloud-nest-v1/wwjcloud/test/test.controller.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Controller, Post, Body, Get } from '@nestjs/common';
import { TestService } from './test.service';
import { Public } from '../src/core/decorators/public.decorator';
@Controller('test')
export class TestController {
constructor(private readonly testService: TestService) {}
@Get('status')
@Public()
getStatus() {
return {
message: 'Test module is working',
timestamp: new Date().toISOString(),
services: {
redis: 'available',
kafka: 'available',
},
};
}
@Post('kafka')
@Public()
async testKafka(@Body() data: Record<string, any>) {
try {
await this.testService.publishKafkaEvent('test-topic', {
message: 'Hello from WWJCloud Test Module!',
data,
timestamp: new Date().toISOString(),
});
return {
success: true,
message: 'Event published to Kafka successfully',
topic: 'test-topic',
data,
};
} catch (error) {
return {
success: false,
message: 'Failed to publish event to Kafka',
error: error instanceof Error ? error.message : String(error),
};
}
}
@Post('redis')
@Public()
async testRedis(@Body() data: Record<string, any>) {
try {
const jobId = await this.testService.enqueueRedisJob('test-job', {
message: 'Hello from WWJCloud Test Module!',
data,
timestamp: new Date().toISOString(),
});
return {
success: true,
message: 'Job queued to Redis successfully',
jobId,
data,
};
} catch (error) {
return {
success: false,
message: 'Failed to queue job to Redis',
error: error instanceof Error ? error.message : String(error),
};
}
}
}