From 4b877108784266dc2f9e99b4f95d7d93791f2b62 Mon Sep 17 00:00:00 2001 From: PARK BYUNG JUN Date: Thu, 18 Aug 2022 07:14:27 +0000 Subject: [PATCH] list_vendors is added --- src/app/app.module.ts | 4 ++ .../partner/components/list.component.ts | 11 +++++ src/app/modules/polyglot/api/api.module.ts | 16 ++++++ .../polyglot/api/services/api.service.ts | 49 +++++++++++++++++++ .../modules/polyglot/api/services/index.ts | 5 ++ 5 files changed, 85 insertions(+) create mode 100644 src/app/modules/polyglot/api/api.module.ts create mode 100644 src/app/modules/polyglot/api/services/api.service.ts create mode 100644 src/app/modules/polyglot/api/services/index.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index cd71169..e4bf6bd 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -31,6 +31,8 @@ import { MemberLevelModule } from 'app/modules/polyglot/member_level/member_leve import { MemberModule } from 'app/modules/polyglot/member/member.module'; import { SiteModule } from 'app/modules/polyglot/site/site.module'; +import { ApiModule } from 'app/modules/polyglot/api/api.module'; + const routerConfig: ExtraOptions = { preloadingStrategy: PreloadAllModules, scrollPositionRestoration: 'enabled', @@ -70,6 +72,8 @@ const routerConfig: ExtraOptions = { MemberLevelModule.forRoot(), MemberModule.forRoot(), SiteModule.forRoot(), + + ApiModule.forRoot(), ], bootstrap: [AppComponent], }) diff --git a/src/app/modules/admin/member/partner/components/list.component.ts b/src/app/modules/admin/member/partner/components/list.component.ts index c49d604..a10a95b 100644 --- a/src/app/modules/admin/member/partner/components/list.component.ts +++ b/src/app/modules/admin/member/partner/components/list.component.ts @@ -54,6 +54,7 @@ import { ListMembersResponse, } from 'app/modules/proto/c2se/member_pb'; import { Pagination } from 'app/modules/proto/protobuf/pagination_pb'; +import { ApiService } from 'app/modules/polyglot/api/services/api.service'; @Component({ selector: 'partner-list', templateUrl: './list.component.html', @@ -119,6 +120,7 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { private _activatedRoute: ActivatedRoute, private _partnerService: PartnerService, private __memberService: MemberService, + private __apiService: ApiService, private router: Router, private _matDialog: MatDialog @@ -190,6 +192,15 @@ export class ListComponent implements OnInit, AfterViewInit, OnDestroy { // Mark for check this._changeDetectorRef.markForCheck(); }); + + this.__apiService + .listBanks() + .then((l) => { + console.log('list', l.getVendorsList()); + }) + .catch((e) => { + console.log('error', e); + }); } /** diff --git a/src/app/modules/polyglot/api/api.module.ts b/src/app/modules/polyglot/api/api.module.ts new file mode 100644 index 0000000..416c5f5 --- /dev/null +++ b/src/app/modules/polyglot/api/api.module.ts @@ -0,0 +1,16 @@ +import { ModuleWithProviders, NgModule } from '@angular/core'; + +import { SERVICES } from './services'; + +@NgModule({}) +export class ApiRootModule {} + +@NgModule({}) +export class ApiModule { + public static forRoot(): ModuleWithProviders { + return { + ngModule: ApiRootModule, + providers: [...SERVICES], + }; + } +} diff --git a/src/app/modules/polyglot/api/services/api.service.ts b/src/app/modules/polyglot/api/services/api.service.ts new file mode 100644 index 0000000..98bfe59 --- /dev/null +++ b/src/app/modules/polyglot/api/services/api.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@angular/core'; +import { NatsService } from 'app/core/nats/services/nats.service'; + +import { Error } from 'app/modules/proto/protobuf/rpc_pb'; + +import { + ListVendorsRequest, + ListVendorsResponse, +} from 'app/modules/proto/c2se/api/vendor_pb'; +import { SUBJECT_LIST_VENDORS } from 'app/modules/proto/c2se/backend/api/vendor_pb'; + +@Injectable({ + providedIn: 'root', +}) +export class ApiService { + /** + * Constructor + */ + constructor(private __natsService: NatsService) {} + + // ----------------------------------------------------------------------------------------------------- + // @ Accessors + // ----------------------------------------------------------------------------------------------------- + + // ----------------------------------------------------------------------------------------------------- + // @ Public methods + // ----------------------------------------------------------------------------------------------------- + + listBanks(): Promise { + return new Promise((resolve, reject) => { + let req = new ListVendorsRequest(); + + this.__natsService + .request( + SUBJECT_LIST_VENDORS, + req.serializeBinary(), + ListVendorsResponse.deserializeBinary + ) + .then((result) => { + console.log('success', result, result.getVendorsList()); + return resolve(result); + }) + .catch((e: Error) => { + console.log('failed', e); + reject(e); + }); + }); + } +} diff --git a/src/app/modules/polyglot/api/services/index.ts b/src/app/modules/polyglot/api/services/index.ts new file mode 100644 index 0000000..23dfd5a --- /dev/null +++ b/src/app/modules/polyglot/api/services/index.ts @@ -0,0 +1,5 @@ +import { Type } from '@angular/core'; + +import { ApiService } from './api.service'; + +export const SERVICES: Type[] = [ApiService];