Skip to content

Commit 7c41207

Browse files
authored
Add base code for question service (#17)
1 parent f268b4a commit 7c41207

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+18086
-31
lines changed

backend/gateway-service/src/app.controller.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Module } from '@nestjs/common';
2-
import { AppController } from './app.controller';
3-
import { AppService } from './app.service';
42
import { ClientsModule, Transport } from '@nestjs/microservices';
3+
import { UserController } from './user/user.controller';
4+
import { UserService } from './user/user.service';
5+
import { QuestionService } from './question/question.service';
6+
import { QuestionController } from './question/questions.controller';
57

68
@Module({
79
imports: [
@@ -11,12 +13,20 @@ import { ClientsModule, Transport } from '@nestjs/microservices';
1113
transport: Transport.TCP,
1214
options: {
1315
host: '127.0.0.1',
14-
port: 3001, // Ensure the port matches the event producer
16+
port: 3001,
17+
},
18+
},
19+
{
20+
name: 'QUESTION_SERVICE',
21+
transport: Transport.TCP,
22+
options: {
23+
host: '127.0.0.1',
24+
port: 3002,
1525
},
1626
},
1727
]),
1828
],
19-
controllers: [AppController],
20-
providers: [AppService],
29+
controllers: [UserController, QuestionController],
30+
providers: [UserService, QuestionService],
2131
})
2232
export class AppModule {}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Inject, Injectable } from '@nestjs/common';
2+
import { ClientProxy } from '@nestjs/microservices';
3+
4+
@Injectable()
5+
export class QuestionService {
6+
constructor(
7+
@Inject('QUESTION_SERVICE') private readonly questionClient: ClientProxy,
8+
) {}
9+
10+
getHello(): string {
11+
return 'This is the questions service!';
12+
}
13+
14+
getQuestions() {
15+
return this.questionClient.send({ cmd: 'get_questions' }, {});
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Body, Controller, Get, Post } from '@nestjs/common';
2+
import { QuestionService } from './question.service';
3+
4+
@Controller('question')
5+
export class QuestionController {
6+
constructor(private readonly questionService: QuestionService) {}
7+
8+
@Get()
9+
getHello(): string {
10+
return this.questionService.getHello();
11+
}
12+
13+
@Get('questions')
14+
getQuestions() {
15+
return this.questionService.getQuestions();
16+
}
17+
}
File renamed without changes.
File renamed without changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Body, Controller, Get, Post } from '@nestjs/common';
2+
import { CreateUserDto } from './dto/create-user.dto';
3+
import { UserService } from './user.service';
4+
5+
@Controller('user')
6+
export class UserController {
7+
constructor(private readonly userService: UserService) {}
8+
9+
@Get()
10+
getHello(): string {
11+
return this.userService.getHello();
12+
}
13+
14+
@Post()
15+
createUser(@Body() createUserDto: CreateUserDto) {
16+
return this.userService.createUser(createUserDto);
17+
}
18+
}

backend/gateway-service/src/app.service.ts renamed to backend/gateway-service/src/user/user.service.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import { ClientProxy } from '@nestjs/microservices';
33
import { CreateUserDto } from './dto/create-user.dto';
44

55
@Injectable()
6-
export class AppService {
7-
6+
export class UserService {
87
constructor(
98
@Inject('USER_SERVICE') private readonly userClient: ClientProxy,
109
) {}
1110

1211
getHello(): string {
13-
return 'Hello World!';
12+
return 'This is the user service!';
1413
}
1514

1615
createUser(createUserDto: CreateUserDto) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
parserOptions: {
4+
project: 'tsconfig.json',
5+
tsconfigRootDir: __dirname,
6+
sourceType: 'module',
7+
},
8+
plugins: ['@typescript-eslint/eslint-plugin'],
9+
extends: [
10+
'plugin:@typescript-eslint/recommended',
11+
'plugin:prettier/recommended',
12+
],
13+
root: true,
14+
env: {
15+
node: true,
16+
jest: true,
17+
},
18+
ignorePatterns: ['.eslintrc.js'],
19+
rules: {
20+
'@typescript-eslint/interface-name-prefix': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/explicit-module-boundary-types': 'off',
23+
'@typescript-eslint/no-explicit-any': 'off',
24+
},
25+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# compiled output
2+
/dist
3+
/node_modules
4+
/build
5+
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
pnpm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
lerna-debug.log*
14+
15+
# OS
16+
.DS_Store
17+
18+
# Tests
19+
/coverage
20+
/.nyc_output
21+
22+
# IDEs and editors
23+
/.idea
24+
.project
25+
.classpath
26+
.c9/
27+
*.launch
28+
.settings/
29+
*.sublime-workspace
30+
31+
# IDE - VSCode
32+
.vscode/*
33+
!.vscode/settings.json
34+
!.vscode/tasks.json
35+
!.vscode/launch.json
36+
!.vscode/extensions.json
37+
38+
# dotenv environment variable files
39+
.env
40+
.env.development.local
41+
.env.test.local
42+
.env.production.local
43+
.env.local
44+
45+
# temp directory
46+
.temp
47+
.tmp
48+
49+
# Runtime data
50+
pids
51+
*.pid
52+
*.seed
53+
*.pid.lock
54+
55+
# Diagnostic reports (https://nodejs.org/api/report.html)
56+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

0 commit comments

Comments
 (0)