From e07e19261ea808dbc6202b9c4c97317511244bbe Mon Sep 17 00:00:00 2001 From: sbriat Date: Mon, 24 Apr 2023 16:44:52 +0200 Subject: [PATCH] wip --- src/app.module.ts | 2 + src/modules/ad/ad.modules.ts | 34 +++++++++++++++ .../primaries/ad-messager.controller.ts | 19 +++++++++ src/modules/ad/domain/entities/ad.ts | 41 +++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 src/modules/ad/ad.modules.ts create mode 100644 src/modules/ad/adapters/primaries/ad-messager.controller.ts create mode 100644 src/modules/ad/domain/entities/ad.ts diff --git a/src/app.module.ts b/src/app.module.ts index 69bca0e..8236fec 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -5,6 +5,7 @@ import { ConfigModule } from '@nestjs/config'; import { ConfigurationModule } from './modules/configuration/configuration.module'; import { HealthModule } from './modules/health/health.module'; import { MatcherModule } from './modules/matcher/matcher.module'; +import { AdModule } from './modules/ad/ad.modules'; @Module({ imports: [ @@ -13,6 +14,7 @@ import { MatcherModule } from './modules/matcher/matcher.module'; ConfigurationModule, HealthModule, MatcherModule, + AdModule, ], controllers: [], providers: [], diff --git a/src/modules/ad/ad.modules.ts b/src/modules/ad/ad.modules.ts new file mode 100644 index 0000000..bb8b761 --- /dev/null +++ b/src/modules/ad/ad.modules.ts @@ -0,0 +1,34 @@ +import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq'; +import { Module } from '@nestjs/common'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { AdMessagerController } from './adapters/primaries/ad-messager.controller'; + +@Module({ + imports: [ + RabbitMQModule.forRootAsync(RabbitMQModule, { + imports: [ConfigModule], + useFactory: async (configService: ConfigService) => ({ + exchanges: [ + { + name: configService.get('RMQ_EXCHANGE'), + type: 'topic', + }, + ], + handlers: { + adCreated: { + exchange: configService.get('RMQ_EXCHANGE'), + routingKey: 'ad.created', + }, + }, + uri: configService.get('RMQ_URI'), + connectionInitOptions: { wait: true }, + enableControllerDiscovery: true, + }), + inject: [ConfigService], + }), + ], + controllers: [AdMessagerController], + providers: [], + exports: [], +}) +export class AdModule {} diff --git a/src/modules/ad/adapters/primaries/ad-messager.controller.ts b/src/modules/ad/adapters/primaries/ad-messager.controller.ts new file mode 100644 index 0000000..6d8e1ab --- /dev/null +++ b/src/modules/ad/adapters/primaries/ad-messager.controller.ts @@ -0,0 +1,19 @@ +import { RabbitSubscribe } from '@golevelup/nestjs-rabbitmq'; +import { Controller } from '@nestjs/common'; +// import { Ad } from '../../domain/entities/ad'; + +@Controller() +export class AdMessagerController { + @RabbitSubscribe({ + name: 'adCreated', + }) + public adCreatedHandler(message: string) { + console.log(JSON.parse(message)); + // try { + // const createdAd: Ad = JSON.parse(message); + // console.log(createdAd); + // } catch (e) { + // console.log('error', e); + // } + } +} diff --git a/src/modules/ad/domain/entities/ad.ts b/src/modules/ad/domain/entities/ad.ts new file mode 100644 index 0000000..b4725ad --- /dev/null +++ b/src/modules/ad/domain/entities/ad.ts @@ -0,0 +1,41 @@ +import { AutoMap } from '@automapper/classes'; + +export class Ad { + @AutoMap() + uuid: string; + + driver: boolean; + passenger: boolean; + frequency: number; + fromDate: string; + toDate: string; + monTime: string; + tueTime: string; + wedTime: string; + thuTime: string; + friTime: string; + satTime: string; + sunTime: string; + monMargin: number; + tueMargin: number; + wedMargin: number; + thuMargin: number; + friMargin: number; + satMargin: number; + sunMargin: number; + driverDuration: number; + driverDistance: number; + passengerDuration: number; + passengerDistance: number; + originType: number; + destinationType: number; + waypoints: []; + direction: string; + fwdAzimuth: number; + backAzimuth: number; + seatsDriver: number; + seatsPassenger: number; + seatsUsed: number; + createdAt: string; + updatedAt: string; +}