add messager presenter

This commit is contained in:
Gsk54 2023-01-26 15:55:06 +01:00
parent 1b7c131d1c
commit 067d8a79af
5 changed files with 37 additions and 3 deletions

View File

@ -8,6 +8,10 @@ Each item consists in :
- a **key** : the key of the configuration item (a string) - a **key** : the key of the configuration item (a string)
- a **value** : the value of the configuration item (always a string, each service must cast the value if needed) - a **value** : the value of the configuration item (always a string, each service must cast the value if needed)
This service centralizes the configuration items, but theoratically each service should "push" its items toward the configuration service.
Practically, it's the other way round as it's easier to use this configuration service as the single source of truth. This is why configuration items key and domain are immutable : services may use hardcoded domain-key pairs. Therefore, only values can be updated.
## Available domains ## Available domains
- **USER** : user related configuration item - **USER** : user related configuration item
@ -85,7 +89,7 @@ The app exposes the following [gRPC](https://grpc.io/) services :
} }
``` ```
- **Update** : update a configuration item - **Update** : update a configuration item value
```json ```json
{ {

View File

@ -0,0 +1,13 @@
import { AutoMap } from '@automapper/classes';
import { Domain } from '../../domain/dtos/domain.enum';
export class ConfigurationMessagerPresenter {
@AutoMap()
domain: Domain;
@AutoMap()
key: string;
@AutoMap()
value: string;
}

View File

@ -1,6 +1,7 @@
import { Mapper } from '@automapper/core'; import { Mapper } from '@automapper/core';
import { InjectMapper } from '@automapper/nestjs'; import { InjectMapper } from '@automapper/nestjs';
import { CommandHandler } from '@nestjs/cqrs'; import { CommandHandler } from '@nestjs/cqrs';
import { ConfigurationMessagerPresenter } from '../../adapters/secondaries/configuration-messager.presenter';
import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager'; import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager';
import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository';
import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
@ -28,7 +29,13 @@ export class CreateConfigurationUseCase {
const configuration = await this._repository.create(entity); const configuration = await this._repository.create(entity);
this._configurationMessager.publish( this._configurationMessager.publish(
'create', 'create',
JSON.stringify(configuration), JSON.stringify(
this._mapper.map(
configuration,
Configuration,
ConfigurationMessagerPresenter,
),
),
); );
this._loggingMessager.publish( this._loggingMessager.publish(
'configuration.create.info', 'configuration.create.info',

View File

@ -1,6 +1,7 @@
import { Mapper } from '@automapper/core'; import { Mapper } from '@automapper/core';
import { InjectMapper } from '@automapper/nestjs'; import { InjectMapper } from '@automapper/nestjs';
import { CommandHandler } from '@nestjs/cqrs'; import { CommandHandler } from '@nestjs/cqrs';
import { ConfigurationMessagerPresenter } from '../../adapters/secondaries/configuration-messager.presenter';
import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager'; import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager';
import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository';
import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
@ -31,7 +32,13 @@ export class UpdateConfigurationUseCase {
); );
this._configurationMessager.publish( this._configurationMessager.publish(
'update', 'update',
JSON.stringify(command.updateConfigurationRequest), JSON.stringify(
this._mapper.map(
configuration,
Configuration,
ConfigurationMessagerPresenter,
),
),
); );
this._loggingMessager.publish( this._loggingMessager.publish(
'configuration.update.info', 'configuration.update.info',

View File

@ -2,6 +2,7 @@ import { createMap, forMember, ignore, Mapper } from '@automapper/core';
import { AutomapperProfile, InjectMapper } from '@automapper/nestjs'; import { AutomapperProfile, InjectMapper } from '@automapper/nestjs';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { ConfigurationPresenter } from '../adapters/primaries/configuration.presenter'; import { ConfigurationPresenter } from '../adapters/primaries/configuration.presenter';
import { ConfigurationMessagerPresenter } from '../adapters/secondaries/configuration-messager.presenter';
import { CreateConfigurationRequest } from '../domain/dtos/create-configuration.request'; import { CreateConfigurationRequest } from '../domain/dtos/create-configuration.request';
import { UpdateConfigurationRequest } from '../domain/dtos/update-configuration.request'; import { UpdateConfigurationRequest } from '../domain/dtos/update-configuration.request';
import { Configuration } from '../domain/entities/configuration'; import { Configuration } from '../domain/entities/configuration';
@ -24,6 +25,8 @@ export class ConfigurationProfile extends AutomapperProfile {
Configuration, Configuration,
forMember((dest) => dest.uuid, ignore()), forMember((dest) => dest.uuid, ignore()),
); );
createMap(mapper, Configuration, ConfigurationMessagerPresenter);
}; };
} }
} }