create ad, WIP

This commit is contained in:
sbriat
2023-05-12 16:23:42 +02:00
parent da96f52c1e
commit e950efe221
24 changed files with 382 additions and 283 deletions

View File

@@ -75,15 +75,21 @@ export class GraphhopperGeorouter implements IGeorouter {
this.getUrl(),
'&point=',
path.points
.map((point) => [point.lat, point.lon].join())
.map((point) => [point.lat, point.lon].join('%2C'))
.join('&point='),
].join('');
const route = await lastValueFrom(
this.httpService.get(url).pipe(
map((res) => (res.data ? this.createRoute(res) : undefined)),
catchError((error: AxiosError) => {
if (error.code == AxiosError.ERR_BAD_REQUEST) {
throw new GeographyException(
ExceptionCode.OUT_OF_RANGE,
'No route found for given coordinates',
);
}
throw new GeographyException(
ExceptionCode.INTERNAL,
ExceptionCode.UNAVAILABLE,
'Georouter unavailable : ' + error.message,
);
}),

View File

@@ -0,0 +1,11 @@
import { Coordinates } from '../../domain/entities/coordinates';
import { IEncodeDirection } from '../../domain/interfaces/direction-encoder.interface';
export class PostgresDirectionEncoder implements IEncodeDirection {
encode = (coordinates: Coordinates[]): string =>
[
"'LINESTRING(",
coordinates.map((point) => [point.lon, point.lat].join(' ')).join(),
")'",
].join('');
}

View File

@@ -0,0 +1,5 @@
import { Coordinates } from '../entities/coordinates';
export interface IEncodeDirection {
encode(coordinates: Coordinates[]): string;
}

View File

@@ -1,13 +1,11 @@
export class GeographyException implements Error {
name: string;
code: number;
message: string;
constructor(private _code: number, private _message: string) {
constructor(code: number, message: string) {
this.name = 'GeographyException';
this.message = _message;
}
get code(): number {
return this._code;
this.code = code;
this.message = message;
}
}