divide domain to ecosystem / engine

This commit is contained in:
sbriat 2023-04-21 10:13:22 +02:00
parent 0a4c4bdf5a
commit a54694c5a9
28 changed files with 132 additions and 50 deletions

View File

@ -6,11 +6,11 @@ import { GrpcMethod, RpcException } from '@nestjs/microservices';
import { RpcValidationPipe } from 'src/modules/utils/pipes/rpc.validation-pipe'; import { RpcValidationPipe } from 'src/modules/utils/pipes/rpc.validation-pipe';
import { MatchRequest } from '../../domain/dtos/match.request'; import { MatchRequest } from '../../domain/dtos/match.request';
import { ICollection } from 'src/modules/database/src/interfaces/collection.interface'; import { ICollection } from 'src/modules/database/src/interfaces/collection.interface';
import { Match } from '../../domain/entities/match';
import { MatchQuery } from '../../queries/match.query'; import { MatchQuery } from '../../queries/match.query';
import { MatchPresenter } from '../secondaries/match.presenter'; import { MatchPresenter } from '../secondaries/match.presenter';
import { DefaultParamsProvider } from '../secondaries/default-params.provider'; import { DefaultParamsProvider } from '../secondaries/default-params.provider';
import { GeorouterCreator } from '../secondaries/georouter-creator'; import { GeorouterCreator } from '../secondaries/georouter-creator';
import { Match } from '../../domain/entities/ecosystem/match';
@UsePipes( @UsePipes(
new RpcValidationPipe({ new RpcValidationPipe({

View File

@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { MatcherRepository } from '../../../database/src/domain/matcher-repository'; import { MatcherRepository } from '../../../database/src/domain/matcher-repository';
import { Ad } from '../../domain/entities/ad'; import { Ad } from '../../domain/entities/ecosystem/ad';
@Injectable() @Injectable()
export class AdRepository extends MatcherRepository<Ad> { export class AdRepository extends MatcherRepository<Ad> {

View File

@ -1,14 +1,14 @@
import { HttpService } from '@nestjs/axios'; import { HttpService } from '@nestjs/axios';
import { NamedRoute } from '../../domain/entities/named-route';
import { IGeorouter } from '../../domain/interfaces/georouter.interface'; import { IGeorouter } from '../../domain/interfaces/georouter.interface';
import { GeorouterSettings } from '../../domain/types/georouter-settings.type'; import { GeorouterSettings } from '../../domain/types/georouter-settings.type';
import { Path } from '../../domain/types/path.type'; import { Path } from '../../domain/types/path.type';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { catchError, lastValueFrom, map } from 'rxjs'; import { catchError, lastValueFrom, map } from 'rxjs';
import { AxiosError, AxiosResponse } from 'axios'; import { AxiosError, AxiosResponse } from 'axios';
import { Route } from '../../domain/entities/route';
import { SpacetimePoint } from '../../domain/entities/spacetime-point';
import { IGeodesic } from '../../domain/interfaces/geodesic.interface'; import { IGeodesic } from '../../domain/interfaces/geodesic.interface';
import { NamedRoute } from '../../domain/entities/ecosystem/named-route';
import { Route } from '../../domain/entities/ecosystem/route';
import { SpacetimePoint } from '../../domain/entities/ecosystem/spacetime-point';
@Injectable() @Injectable()
export class GraphhopperGeorouter implements IGeorouter { export class GraphhopperGeorouter implements IGeorouter {

View File

@ -1,5 +1,5 @@
import { Role } from '../types/role.enum'; import { Role } from '../../types/role.enum';
import { Step } from '../types/step.enum'; import { Step } from '../../types/step.enum';
import { Person } from './person'; import { Person } from './person';
export class Actor { export class Actor {

View File

@ -1,9 +1,9 @@
import { IRequestAlgorithmSettings } from '../interfaces/algorithm-settings-request.interface'; import { IRequestAlgorithmSettings } from '../../interfaces/algorithm-settings-request.interface';
import { DefaultAlgorithmSettings } from '../types/default-algorithm-settings.type'; import { DefaultAlgorithmSettings } from '../../types/default-algorithm-settings.type';
import { Algorithm } from '../types/algorithm.enum'; import { Algorithm } from '../../types/algorithm.enum';
import { TimingFrequency } from '../types/timing'; import { TimingFrequency } from '../../types/timing';
import { ICreateGeorouter } from '../interfaces/georouter-creator.interface'; import { ICreateGeorouter } from '../../interfaces/georouter-creator.interface';
import { IGeorouter } from '../interfaces/georouter.interface'; import { IGeorouter } from '../../interfaces/georouter.interface';
export class AlgorithmSettings { export class AlgorithmSettings {
_algorithmSettingsRequest: IRequestAlgorithmSettings; _algorithmSettingsRequest: IRequestAlgorithmSettings;

View File

@ -1,16 +1,16 @@
import { MatcherException } from '../../exceptions/matcher.exception'; import { MatcherException } from '../../../exceptions/matcher.exception';
import { IRequestGeography } from '../interfaces/geography-request.interface'; import { IRequestGeography } from '../../interfaces/geography-request.interface';
import { PointType } from '../types/geography.enum'; import { PointType } from '../../types/geography.enum';
import { Point } from '../types/point.type'; import { Point } from '../../types/point.type';
import { find } from 'geo-tz'; import { find } from 'geo-tz';
import { Route } from './route'; import { Route } from './route';
import { Role } from '../types/role.enum'; import { Role } from '../../types/role.enum';
import { IGeorouter } from '../interfaces/georouter.interface'; import { IGeorouter } from '../../interfaces/georouter.interface';
import { Waypoint } from './waypoint'; import { Waypoint } from './waypoint';
import { Actor } from './actor'; import { Actor } from './actor';
import { Person } from './person'; import { Person } from './person';
import { Step } from '../types/step.enum'; import { Step } from '../../types/step.enum';
import { Path } from '../types/path.type'; import { Path } from '../../types/path.type';
export class Geography { export class Geography {
_geographyRequest: IRequestGeography; _geographyRequest: IRequestGeography;

View File

@ -1,4 +1,4 @@
import { IRequestPerson } from '../interfaces/person-request.interface'; import { IRequestPerson } from '../../interfaces/person-request.interface';
export class Person { export class Person {
_personRequest: IRequestPerson; _personRequest: IRequestPerson;

View File

@ -1,4 +1,4 @@
import { IRequestRequirement } from '../interfaces/requirement-request.interface'; import { IRequestRequirement } from '../../interfaces/requirement-request.interface';
export class Requirement { export class Requirement {
_requirementRequest: IRequestRequirement; _requirementRequest: IRequestRequirement;

View File

@ -1,5 +1,5 @@
import { IGeodesic } from '../interfaces/geodesic.interface'; import { IGeodesic } from '../../interfaces/geodesic.interface';
import { Point } from '../types/point.type'; import { Point } from '../../types/point.type';
import { SpacetimePoint } from './spacetime-point'; import { SpacetimePoint } from './spacetime-point';
import { Waypoint } from './waypoint'; import { Waypoint } from './waypoint';

View File

@ -1,8 +1,8 @@
import { MatcherException } from '../../exceptions/matcher.exception'; import { MatcherException } from '../../../exceptions/matcher.exception';
import { MarginDurations } from '../types/margin-durations.type'; import { MarginDurations } from '../../types/margin-durations.type';
import { IRequestTime } from '../interfaces/time-request.interface'; import { IRequestTime } from '../../interfaces/time-request.interface';
import { TimingDays, TimingFrequency, Days } from '../types/timing'; import { TimingDays, TimingFrequency, Days } from '../../types/timing';
import { Schedule } from '../types/schedule.type'; import { Schedule } from '../../types/schedule.type';
export class Time { export class Time {
_timeRequest: IRequestTime; _timeRequest: IRequestTime;

View File

@ -1,4 +1,4 @@
import { Point } from '../types/point.type'; import { Point } from '../../types/point.type';
import { Actor } from './actor'; import { Actor } from './actor';
export class Waypoint { export class Waypoint {

View File

@ -0,0 +1,5 @@
import { Person } from '../ecosystem/person';
export class Candidate {
person: Person;
}

View File

@ -0,0 +1,15 @@
import { MatchQuery } from 'src/modules/matcher/queries/match.query';
import { Processor } from '../processor.abstract';
import { Candidate } from '../candidate';
export abstract class AlgorithmFactory {
_matchQuery: MatchQuery;
_candidates: Array<Candidate>;
constructor(matchQuery: MatchQuery) {
this._matchQuery = matchQuery;
this._candidates = [];
}
abstract createProcessors(): Array<Processor>;
}

View File

@ -0,0 +1,9 @@
import { AlgorithmFactory } from './algorithm-factory.abstract';
import { Processor } from '../processor.abstract';
import { ClassicWaypointsCompleter } from '../processor/completer/classic-waypoint.completer.processor';
export class ClassicAlgorithmFactory extends AlgorithmFactory {
createProcessors(): Array<Processor> {
return [new ClassicWaypointsCompleter(this._matchQuery)];
}
}

View File

@ -0,0 +1,21 @@
import { MatchQuery } from '../../../queries/match.query';
import { Algorithm } from '../../types/algorithm.enum';
import { Match } from '../ecosystem/match';
import { Candidate } from './candidate';
import { AlgorithmFactory } from './factory/algorithm-factory.abstract';
import { ClassicAlgorithmFactory } from './factory/classic';
export class Matcher {
match = (matchQuery: MatchQuery): Array<Match> => {
let algorithm: AlgorithmFactory;
switch (matchQuery.algorithmSettings.algorithm) {
case Algorithm.CLASSIC:
algorithm = new ClassicAlgorithmFactory(matchQuery);
}
let candidates: Array<Candidate> = [];
for (const processor of algorithm.createProcessors()) {
candidates = processor.execute(candidates);
}
return [];
};
}

View File

@ -0,0 +1,12 @@
import { MatchQuery } from 'src/modules/matcher/queries/match.query';
import { Candidate } from './candidate';
export abstract class Processor {
_matchQuery: MatchQuery;
constructor(matchQuery: MatchQuery) {
this._matchQuery = matchQuery;
}
abstract execute(candidates: Array<Candidate>): Array<Candidate>;
}

View File

@ -0,0 +1,8 @@
import { Candidate } from '../../candidate';
import { Completer } from './completer.abstract';
export class ClassicWaypointsCompleter extends Completer {
complete(candidates: Array<Candidate>): Array<Candidate> {
return [];
}
}

View File

@ -0,0 +1,9 @@
import { Candidate } from '../../candidate';
import { Processor } from '../../processor.abstract';
export abstract class Completer extends Processor {
execute = (candidates: Array<Candidate>): Array<Candidate> =>
this.complete(candidates);
abstract complete(candidates: Array<Candidate>): Array<Candidate>;
}

View File

@ -4,8 +4,8 @@ import { QueryHandler } from '@nestjs/cqrs';
import { Messager } from '../../adapters/secondaries/messager'; import { Messager } from '../../adapters/secondaries/messager';
import { MatchQuery } from '../../queries/match.query'; import { MatchQuery } from '../../queries/match.query';
import { AdRepository } from '../../adapters/secondaries/ad.repository'; import { AdRepository } from '../../adapters/secondaries/ad.repository';
import { Match } from '../entities/match'; import { Match } from '../entities/ecosystem/match';
import { ICollection } from 'src/modules/database/src/interfaces/collection.interface'; import { ICollection } from '../../../database/src/interfaces/collection.interface';
@QueryHandler(MatchQuery) @QueryHandler(MatchQuery)
export class MatchUseCase { export class MatchUseCase {

View File

@ -1,10 +1,10 @@
import { MatchRequest } from '../domain/dtos/match.request'; import { MatchRequest } from '../domain/dtos/match.request';
import { Geography } from '../domain/entities/geography'; import { Geography } from '../domain/entities/ecosystem/geography';
import { Person } from '../domain/entities/person'; import { Person } from '../domain/entities/ecosystem/person';
import { Requirement } from '../domain/entities/requirement'; import { Requirement } from '../domain/entities/ecosystem/requirement';
import { Role } from '../domain/types/role.enum'; import { Role } from '../domain/types/role.enum';
import { AlgorithmSettings } from '../domain/entities/algorithm-settings'; import { AlgorithmSettings } from '../domain/entities/ecosystem/algorithm-settings';
import { Time } from '../domain/entities/time'; import { Time } from '../domain/entities/ecosystem/time';
import { IDefaultParams } from '../domain/types/default-params.type'; import { IDefaultParams } from '../domain/types/default-params.type';
import { IGeorouter } from '../domain/interfaces/georouter.interface'; import { IGeorouter } from '../domain/interfaces/georouter.interface';
import { ICreateGeorouter } from '../domain/interfaces/georouter-creator.interface'; import { ICreateGeorouter } from '../domain/interfaces/georouter-creator.interface';

View File

@ -1,10 +1,13 @@
import { Person } from '../../../domain/entities/person'; import { Person } from '../../../../domain/entities/ecosystem/person';
import { Geography, RouteKey } from '../../../domain/entities/geography'; import {
import { Role } from '../../../domain/types/role.enum'; Geography,
import { NamedRoute } from '../../../domain/entities/named-route'; RouteKey,
import { Route } from '../../../domain/entities/route'; } from '../../../../domain/entities/ecosystem/geography';
import { IGeodesic } from '../../../domain/interfaces/geodesic.interface'; import { Role } from '../../../../domain/types/role.enum';
import { PointType } from '../../../domain/types/geography.enum'; import { NamedRoute } from '../../../../domain/entities/ecosystem/named-route';
import { Route } from '../../../../domain/entities/ecosystem/route';
import { IGeodesic } from '../../../../domain/interfaces/geodesic.interface';
import { PointType } from '../../../../domain/types/geography.enum';
const person: Person = new Person( const person: Person = new Person(
{ {

View File

@ -1,4 +1,4 @@
import { Person } from '../../../domain/entities/person'; import { Person } from '../../../../domain/entities/ecosystem/person';
const DEFAULT_IDENTIFIER = 0; const DEFAULT_IDENTIFIER = 0;
const MARGIN_DURATION = 900; const MARGIN_DURATION = 900;

View File

@ -1,6 +1,6 @@
import { Route } from '../../../domain/entities/route'; import { Route } from '../../../../domain/entities/ecosystem/route';
import { SpacetimePoint } from '../../../domain/entities/spacetime-point'; import { SpacetimePoint } from '../../../../domain/entities/ecosystem/spacetime-point';
import { Waypoint } from '../../../domain/entities/waypoint'; import { Waypoint } from '../../../../domain/entities/ecosystem/waypoint';
const mockGeodesic = { const mockGeodesic = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars

View File

@ -1,4 +1,4 @@
import { Time } from '../../../domain/entities/time'; import { Time } from '../../../../domain/entities/ecosystem/time';
const MARGIN_DURATION = 900; const MARGIN_DURATION = 900;
const VALIDITY_DURATION = 365; const VALIDITY_DURATION = 365;