remove waypoints where not relevant

This commit is contained in:
sbriat
2023-09-14 17:07:38 +02:00
parent c65a5b50c2
commit f69afc4481
38 changed files with 273 additions and 461 deletions

View File

@@ -1,6 +1,6 @@
import { Route, Waypoint } from '../../domain/route.types';
import { Route, Point } from '../../domain/route.types';
import { GeorouterSettings } from '../types/georouter-settings.type';
export interface GeorouterPort {
route(waypoints: Waypoint[], settings: GeorouterSettings): Promise<Route>;
route(waypoints: Point[], settings: GeorouterSettings): Promise<Route>;
}

View File

@@ -1,12 +1,12 @@
import { QueryBase } from '@mobicoop/ddd-library';
import { GeorouterSettings } from '../../types/georouter-settings.type';
import { Waypoint } from '@modules/geography/core/domain/route.types';
import { Point } from '@modules/geography/core/domain/route.types';
export class GetRouteQuery extends QueryBase {
readonly waypoints: Waypoint[];
readonly waypoints: Point[];
readonly georouterSettings: GeorouterSettings;
constructor(waypoints: Waypoint[], georouterSettings: GeorouterSettings) {
constructor(waypoints: Point[], georouterSettings: GeorouterSettings) {
super();
this.waypoints = waypoints;
this.georouterSettings = georouterSettings;

View File

@@ -1,7 +1,6 @@
import { GeorouterPort } from '../application/ports/georouter.port';
import { GeorouterSettings } from '../application/types/georouter-settings.type';
import { PointProps } from './value-objects/point.value-object';
import { WaypointProps } from './value-objects/waypoint.value-object';
// All properties that a Route has
export interface RouteProps {
@@ -15,7 +14,7 @@ export interface RouteProps {
// Properties that are needed for a Route creation
export interface CreateRouteProps {
waypoints: WaypointProps[];
waypoints: PointProps[];
georouter: GeorouterPort;
georouterSettings: GeorouterSettings;
}
@@ -36,13 +35,7 @@ export type Point = {
lat: number;
};
export type Waypoint = Point & {
position: number;
};
export type Spacetime = {
export type Step = Point & {
duration: number;
distance?: number;
};
export type Step = Point & Spacetime;

View File

@@ -1,32 +0,0 @@
import { ArgumentInvalidException, ValueObject } from '@mobicoop/ddd-library';
import { PointProps } from './point.value-object';
/** Note:
* Value Objects with multiple properties can contain
* other Value Objects inside if needed.
* */
export interface WaypointProps extends PointProps {
position: number;
}
export class Waypoint extends ValueObject<WaypointProps> {
get position(): number {
return this.props.position;
}
get lon(): number {
return this.props.lon;
}
get lat(): number {
return this.props.lat;
}
protected validate(props: WaypointProps): void {
if (props.position < 0)
throw new ArgumentInvalidException(
'position must be greater than or equal to 0',
);
}
}

View File

@@ -2,7 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { HttpService } from '@nestjs/axios';
import { GeorouterPort } from '../core/application/ports/georouter.port';
import { GeorouterSettings } from '../core/application/types/georouter-settings.type';
import { Route, Step, Waypoint } from '../core/domain/route.types';
import { Route, Step, Point } from '../core/domain/route.types';
import { DefaultParamsProviderPort } from '../core/application/ports/default-params-provider.port';
import { GEODESIC, PARAMS_PROVIDER } from '../geography.di-tokens';
import { catchError, lastValueFrom, map } from 'rxjs';
@@ -31,7 +31,7 @@ export class GraphhopperGeorouter implements GeorouterPort {
}
route = async (
waypoints: Waypoint[],
waypoints: Point[],
settings: GeorouterSettings,
): Promise<Route> => {
this._setDefaultUrlArgs();
@@ -57,12 +57,12 @@ export class GraphhopperGeorouter implements GeorouterPort {
}
};
private _getRoute = async (waypoints: Waypoint[]): Promise<Route> => {
private _getRoute = async (waypoints: Point[]): Promise<Route> => {
const url: string = [
this.getUrl(),
'&point=',
waypoints
.map((waypoint: Waypoint) => [waypoint.lat, waypoint.lon].join('%2C'))
.map((point: Point) => [point.lat, point.lon].join('%2C'))
.join('&point='),
].join('');
return await lastValueFrom(

View File

@@ -1,5 +1,5 @@
import { Waypoint } from '@modules/geography/core/domain/route.types';
import { Point } from '@modules/geography/core/domain/route.types';
export type GetRouteRequestDto = {
waypoints: Waypoint[];
waypoints: Point[];
};

View File

@@ -2,17 +2,15 @@ import { GeorouterPort } from '@modules/geography/core/application/ports/georout
import { GetRouteQuery } from '@modules/geography/core/application/queries/get-route/get-route.query';
import { GetRouteQueryHandler } from '@modules/geography/core/application/queries/get-route/get-route.query-handler';
import { RouteEntity } from '@modules/geography/core/domain/route.entity';
import { Waypoint } from '@modules/geography/core/domain/route.types';
import { Point } from '@modules/geography/core/domain/route.types';
import { GEOROUTER } from '@modules/geography/geography.di-tokens';
import { Test, TestingModule } from '@nestjs/testing';
const originWaypoint: Waypoint = {
position: 0,
const originWaypoint: Point = {
lat: 48.689445,
lon: 6.17651,
};
const destinationWaypoint: Waypoint = {
position: 1,
const destinationWaypoint: Point = {
lat: 48.8566,
lon: 2.3522,
};

View File

@@ -44,16 +44,7 @@ const mockGeorouter: GeorouterPort = {
};
const createRouteProps: CreateRouteProps = {
waypoints: [
{
position: 0,
...originPoint,
},
{
position: 1,
...destinationPoint,
},
],
waypoints: [originPoint, destinationPoint],
georouter: mockGeorouter,
georouterSettings: {
points: true,

View File

@@ -1,69 +0,0 @@
import {
ArgumentInvalidException,
ArgumentOutOfRangeException,
} from '@mobicoop/ddd-library';
import { Waypoint } from '@modules/geography/core/domain/value-objects/waypoint.value-object';
describe('Waypoint value object', () => {
it('should create a waypoint value object', () => {
const waypointVO = new Waypoint({
position: 0,
lat: 48.689445,
lon: 6.17651,
});
expect(waypointVO.position).toBe(0);
expect(waypointVO.lat).toBe(48.689445);
expect(waypointVO.lon).toBe(6.17651);
});
it('should throw an exception if position is invalid', () => {
try {
new Waypoint({
position: -1,
lat: 48.689445,
lon: 6.17651,
});
} catch (e: any) {
expect(e).toBeInstanceOf(ArgumentInvalidException);
}
});
it('should throw an exception if longitude is invalid', () => {
try {
new Waypoint({
position: 0,
lat: 48.689445,
lon: 186.17651,
});
} catch (e: any) {
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
}
try {
new Waypoint({
position: 0,
lat: 48.689445,
lon: -186.17651,
});
} catch (e: any) {
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
}
});
it('should throw an exception if latitude is invalid', () => {
try {
new Waypoint({
position: 0,
lat: 148.689445,
lon: 6.17651,
});
} catch (e: any) {
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
}
try {
new Waypoint({
position: 0,
lat: -148.689445,
lon: 6.17651,
});
} catch (e: any) {
expect(e).toBeInstanceOf(ArgumentOutOfRangeException);
}
});
});

View File

@@ -297,12 +297,10 @@ describe('Graphhopper Georouter', () => {
graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 1,
lat: 1,
},
@@ -321,12 +319,10 @@ describe('Graphhopper Georouter', () => {
graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 1,
lat: 1,
},
@@ -344,12 +340,10 @@ describe('Graphhopper Georouter', () => {
const route: Route = await graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 10,
lat: 10,
},
@@ -367,12 +361,10 @@ describe('Graphhopper Georouter', () => {
const route: Route = await graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 10,
lat: 10,
},
@@ -394,12 +386,10 @@ describe('Graphhopper Georouter', () => {
const route: Route = await graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 10,
lat: 10,
},
@@ -419,17 +409,14 @@ describe('Graphhopper Georouter', () => {
const route: Route = await graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 5,
lat: 5,
},
{
position: 2,
lon: 10,
lat: 10,
},
@@ -452,12 +439,10 @@ describe('Graphhopper Georouter', () => {
const route: Route = await graphhopperGeorouter.route(
[
{
position: 0,
lon: 0,
lat: 0,
},
{
position: 1,
lon: 10,
lat: 10,
},

View File

@@ -49,12 +49,10 @@ describe('Get Basic Route Controller', () => {
await getBasicRouteController.get({
waypoints: [
{
position: 0,
lat: 48.689445,
lon: 6.17651,
},
{
position: 1,
lat: 48.8566,
lon: 2.3522,
},