From a66d67cf64beee85fb556c48c17278c1c959f9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=95=8A=E5=B9=B3?= <951984189@qq.com> Date: Fri, 12 Mar 2021 18:55:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E6=96=B0=E5=A2=9Edemo=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/modules/demo/controller/app/goods.ts | 17 +++++++++++-- src/app/modules/demo/service/goods.ts | 26 ++++++++++++++++++++ src/configuration.ts | 1 - 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 src/app/modules/demo/service/goods.ts diff --git a/src/app/modules/demo/controller/app/goods.ts b/src/app/modules/demo/controller/app/goods.ts index 8290352..247ba87 100644 --- a/src/app/modules/demo/controller/app/goods.ts +++ b/src/app/modules/demo/controller/app/goods.ts @@ -1,6 +1,7 @@ -import { Provide } from '@midwayjs/decorator'; +import { Get, Inject, Provide } from '@midwayjs/decorator'; import { CoolController, BaseController } from 'midwayjs-cool-core'; import { DemoAppGoodsEntity } from '../../entity/goods'; +import { DemoGoodsService } from '../../service/goods'; /** * 商品 @@ -10,4 +11,16 @@ import { DemoAppGoodsEntity } from '../../entity/goods'; api: ['add', 'delete', 'update', 'info', 'list', 'page'], entity: DemoAppGoodsEntity, }) -export class DemoAppGoodsController extends BaseController {} +export class DemoAppGoodsController extends BaseController { + @Inject() + demoGoodsService: DemoGoodsService; + + /** + * 请求所有数据 + * @returns + */ + @Get('/all') + async all() { + return this.ok(await this.demoGoodsService.all()); + } +} diff --git a/src/app/modules/demo/service/goods.ts b/src/app/modules/demo/service/goods.ts new file mode 100644 index 0000000..7bf0925 --- /dev/null +++ b/src/app/modules/demo/service/goods.ts @@ -0,0 +1,26 @@ +import { Inject, Provide } from '@midwayjs/decorator'; +import { BaseService, Cache } from 'midwayjs-cool-core'; +import { InjectEntityModel } from '@midwayjs/orm'; +import { Repository } from 'typeorm'; +import { DemoAppGoodsEntity } from '../entity/goods'; +import { ICoolCache } from 'midwayjs-cool-core'; + +/** + * 商品 + */ +@Provide() +export class DemoGoodsService extends BaseService { + @InjectEntityModel(DemoAppGoodsEntity) + demoAppGoodsEntity: Repository; + + @Inject('cool:cache') + coolCache: ICoolCache; + + /** + * 返回所有数据 + */ + @Cache(5) + async all() { + return this.demoAppGoodsEntity.find(); + } +} diff --git a/src/configuration.ts b/src/configuration.ts index 365b3f3..dfe5123 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -36,7 +36,6 @@ export class ContainerLifeCycle implements ILifeCycle { app: Application; // 应用启动完成 async onReady(container?: IMidwayContainer) { - console.log(container.baseDir); } // 应用停止 async onStop() {}