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() {}