Skip to content

Commit

Permalink
call question service endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cyri113 committed Sep 16, 2024
1 parent 8c4caf6 commit 3abbe6e
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 11 deletions.
4 changes: 4 additions & 0 deletions apps/question-service/src/dto/QuestionResult.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class QuestionResult {
label: 'QUESTION' | 'STATEMENT';
score: number;
}
3 changes: 3 additions & 0 deletions apps/question-service/src/dto/QuestionText.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class QuestionText {
text: string;
}
7 changes: 4 additions & 3 deletions apps/question-service/src/question-service.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export class QuestionServiceController {
) { }

@MessagePattern(UpdateEvent.MESSAGE)
async message(@Payload() data): Promise<void> {
const { update } = data;
async message(@Payload() payload): Promise<void> {
const { update } = payload;
const { message } = update;
this.logger.log('Message received', message);
const { data } = await this.questionServiceService.test(message.text);
this.logger.log('Result', data);
}
}
2 changes: 2 additions & 0 deletions apps/question-service/src/question-service.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { QuestionServiceController } from './question-service.controller';
import { QuestionServiceService } from './question-service.service';
import { schemaConfig, rmqConfig, mongoConfig, RmqModule } from '@app/common';
import { ConfigModule } from '@nestjs/config';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [
Expand All @@ -12,6 +13,7 @@ import { ConfigModule } from '@nestjs/config';
isGlobal: true,
}),
RmqModule,
HttpModule,
],
controllers: [QuestionServiceController],
providers: [QuestionServiceService],
Expand Down
14 changes: 12 additions & 2 deletions apps/question-service/src/question-service.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { QuestionResult } from './dto/QuestionResult';
import { AxiosResponse } from 'axios';

@Injectable()
export class QuestionServiceService {
getHello(): string {
return 'Hello World!';
constructor(private readonly httpService: HttpService) { }

test(text: string): Promise<AxiosResponse<QuestionResult>> {
return this.httpService.axiosRef.post(
'http://telegram-question-service-ext-1/test',
{
text,
},
);
}
}
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ services:
container_name: telegram-question
command: npm run start question-service

question-service-ext:
image: ghcr.io/togethercrew/question-service:main
platform: linux/x86_64
ports:
- 80:80

volumes:
mongo_data:
neo4j_data:
Expand Down
52 changes: 47 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test:e2e": "jest --config ./apps/telegram/test/jest-e2e.json"
},
"dependencies": {
"@nestjs/axios": "^3.0.3",
"@nestjs/common": "^10.3.3",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.3.3",
Expand All @@ -28,6 +29,7 @@
"@nestjs/platform-express": "^10.3.3",
"amqp-connection-manager": "^4.1.14",
"amqplib": "^0.10.3",
"axios": "^1.7.7",
"grammy": "^1.22.4",
"joi": "^17.12.2",
"mongoose": "^8.2.0",
Expand Down Expand Up @@ -83,4 +85,4 @@
"^@app/common(|/.*)$": "<rootDir>/libs/common/src/$1"
}
}
}
}

0 comments on commit 3abbe6e

Please sign in to comment.