Skip to content

Commit

Permalink
add example dynamic paramters and di
Browse files Browse the repository at this point in the history
  • Loading branch information
disizali committed May 31, 2021
1 parent 6cdd6bd commit 632e470
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/math-bot/bot.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from "../../packages/common/mod.ts";
import { MathController } from "./math.controller.ts";

@Module({
controllers: [MathController],
})
export class BotModule {}
9 changes: 9 additions & 0 deletions examples/math-bot/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TeaFactory } from "../../packages/core/factory.ts";
import { BotModule } from "./bot.module.ts";

function bootstrap() {
const bot = TeaFactory.create(BotModule, "BOT_TOKEN");
bot.start();
}

bootstrap();
12 changes: 12 additions & 0 deletions examples/math-bot/math.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Hears, Param } from "../../packages/common/mod.ts";
import { MathService } from "./math.service.ts";

@Controller()
export class MathController {
constructor(private mathService: MathService) {}

@Hears("{first:number}+{second:number}")
sum(@Param("first") first: number, @Param("second") second: number) {
return this.mathService.sum(first, second);
}
}
8 changes: 8 additions & 0 deletions examples/math-bot/math.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from "../../packages/common/mod.ts";

@Injectable()
export class MathService {
sum(first: number, second: number) {
return +first + +second;
}
}

0 comments on commit 632e470

Please sign in to comment.