diff --git a/.env.dist b/.env.dist index c4859fc..ceae12f 100644 --- a/.env.dist +++ b/.env.dist @@ -47,19 +47,16 @@ MAX_DETOUR_DURATION_RATIO=0.3 GEOROUTER_TYPE=graphhopper # georouter url GEOROUTER_URL=http://localhost:8989 - -# DEFAULT CARPOOL DEPARTURE TIME MARGIN (in seconds) +# default carpool departure time margin (in seconds) DEPARTURE_TIME_MARGIN=900 - -# DEFAULT ROLE +# default role ROLE=passenger - -# SEATS PROPOSED AS DRIVER / REQUESTED AS PASSENGER +# seats proposes as driver / requested as passenger SEATS_PROPOSED=3 SEATS_REQUESTED=1 - -# ACCEPT ONLY SAME FREQUENCY REQUESTS +# accept only same frequency requests STRICT_FREQUENCY=false - # default timezone TIMEZONE=Europe/Paris +# number of matching results per page +PER_PAGE=10 diff --git a/src/modules/ad/core/application/ports/default-params.type.ts b/src/modules/ad/core/application/ports/default-params.type.ts index 3bee195..9b4c2ca 100644 --- a/src/modules/ad/core/application/ports/default-params.type.ts +++ b/src/modules/ad/core/application/ports/default-params.type.ts @@ -16,4 +16,5 @@ export type DefaultParams = { AZIMUTH_MARGIN: number; MAX_DETOUR_DISTANCE_RATIO: number; MAX_DETOUR_DURATION_RATIO: number; + PER_PAGE: number; }; diff --git a/src/modules/ad/core/application/queries/match/match.query-handler.ts b/src/modules/ad/core/application/queries/match/match.query-handler.ts index fb263fc..17300d1 100644 --- a/src/modules/ad/core/application/queries/match/match.query-handler.ts +++ b/src/modules/ad/core/application/queries/match/match.query-handler.ts @@ -49,6 +49,10 @@ export class MatchQueryHandler implements IQueryHandler { maxDetourDistanceRatio: this._defaultParams.MAX_DETOUR_DISTANCE_RATIO, maxDetourDurationRatio: this._defaultParams.MAX_DETOUR_DURATION_RATIO, }) + .setDefaultPagination({ + page: 1, + perPage: this._defaultParams.PER_PAGE, + }) .setDatesAndSchedule(this.datetimeTransformer); await query.setRoutes(); diff --git a/src/modules/ad/core/application/queries/match/match.query.ts b/src/modules/ad/core/application/queries/match/match.query.ts index 742a663..eadc26a 100644 --- a/src/modules/ad/core/application/queries/match/match.query.ts +++ b/src/modules/ad/core/application/queries/match/match.query.ts @@ -33,8 +33,8 @@ export class MatchQuery extends QueryBase { azimuthMargin?: number; maxDetourDistanceRatio?: number; maxDetourDurationRatio?: number; - readonly page?: number; - readonly perPage?: number; + page?: number; + perPage?: number; driverRoute?: Route; passengerRoute?: Route; backAzimuth?: number; @@ -61,8 +61,8 @@ export class MatchQuery extends QueryBase { this.azimuthMargin = props.azimuthMargin; this.maxDetourDistanceRatio = props.maxDetourDistanceRatio; this.maxDetourDurationRatio = props.maxDetourDurationRatio; - this.page = props.page ?? 1; - this.perPage = props.perPage ?? 10; + this.page = props.page; + this.perPage = props.perPage; this.originWaypoint = this.waypoints.filter( (waypoint: Waypoint) => waypoint.position == 0, )[0]; @@ -124,6 +124,12 @@ export class MatchQuery extends QueryBase { return this; }; + setDefaultPagination = (defaultPagination: DefaultPagination): MatchQuery => { + if (!this.page) this.page = defaultPagination.page; + if (!this.perPage) this.perPage = defaultPagination.perPage; + return this; + }; + setDatesAndSchedule = ( datetimeTransformer: DateTimeTransformerPort, ): MatchQuery => { @@ -243,3 +249,8 @@ interface DefaultAlgorithmParameters { maxDetourDistanceRatio: number; maxDetourDurationRatio: number; } + +interface DefaultPagination { + page: number; + perPage: number; +} diff --git a/src/modules/ad/infrastructure/default-params-provider.ts b/src/modules/ad/infrastructure/default-params-provider.ts index 81f1737..10d7f13 100644 --- a/src/modules/ad/infrastructure/default-params-provider.ts +++ b/src/modules/ad/infrastructure/default-params-provider.ts @@ -18,6 +18,7 @@ const USE_AZIMUTH = true; const AZIMUTH_MARGIN = 10; const MAX_DETOUR_DISTANCE_RATIO = 0.3; const MAX_DETOUR_DURATION_RATIO = 0.3; +const PER_PAGE = 10; @Injectable() export class DefaultParamsProvider implements DefaultParamsProviderPort { @@ -81,5 +82,9 @@ export class DefaultParamsProvider implements DefaultParamsProviderPort { this._configService.get('MAX_DETOUR_DURATION_RATIO') as string, ) : MAX_DETOUR_DURATION_RATIO, + PER_PAGE: + this._configService.get('PER_PAGE') !== undefined + ? parseInt(this._configService.get('PER_PAGE') as string) + : PER_PAGE, }); } diff --git a/src/modules/ad/tests/unit/core/match.query-handler.spec.ts b/src/modules/ad/tests/unit/core/match.query-handler.spec.ts index 9fd930d..1f308f2 100644 --- a/src/modules/ad/tests/unit/core/match.query-handler.spec.ts +++ b/src/modules/ad/tests/unit/core/match.query-handler.spec.ts @@ -72,6 +72,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { AZIMUTH_MARGIN: 10, MAX_DETOUR_DISTANCE_RATIO: 0.3, MAX_DETOUR_DURATION_RATIO: 0.3, + PER_PAGE: 10, }; }, }; diff --git a/src/modules/ad/tests/unit/core/match.query.spec.ts b/src/modules/ad/tests/unit/core/match.query.spec.ts index 14f7415..62ecb04 100644 --- a/src/modules/ad/tests/unit/core/match.query.spec.ts +++ b/src/modules/ad/tests/unit/core/match.query.spec.ts @@ -49,6 +49,7 @@ const defaultParams: DefaultParams = { AZIMUTH_MARGIN: 10, MAX_DETOUR_DISTANCE_RATIO: 0.3, MAX_DETOUR_DURATION_RATIO: 0.3, + PER_PAGE: 10, }; const mockInputDateTimeTransformer: DateTimeTransformerPort = { diff --git a/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts b/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts index 105358a..c23ea19 100644 --- a/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/default-param.provider.spec.ts @@ -34,6 +34,8 @@ const mockConfigServiceWithDefaults = { return 0.5; case 'MAX_DETOUR_DURATION_RATIO': return 0.6; + case 'PER_PAGE': + return 15; default: return 'some_default_value'; } @@ -96,6 +98,7 @@ describe('DefaultParamsProvider', () => { expect(params.AZIMUTH_MARGIN).toBe(15); expect(params.MAX_DETOUR_DISTANCE_RATIO).toBe(0.5); expect(params.MAX_DETOUR_DURATION_RATIO).toBe(0.6); + expect(params.PER_PAGE).toBe(15); }); it('should provide default params if defaults are not set', async () => { @@ -113,5 +116,6 @@ describe('DefaultParamsProvider', () => { expect(params.AZIMUTH_MARGIN).toBe(10); expect(params.MAX_DETOUR_DISTANCE_RATIO).toBe(0.3); expect(params.MAX_DETOUR_DURATION_RATIO).toBe(0.3); + expect(params.PER_PAGE).toBe(10); }); }); diff --git a/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts b/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts index bc4bce3..166b21c 100644 --- a/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/input-datetime-transformer.spec.ts @@ -29,6 +29,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { AZIMUTH_MARGIN: 10, MAX_DETOUR_DISTANCE_RATIO: 0.3, MAX_DETOUR_DURATION_RATIO: 0.3, + PER_PAGE: 10, }; }, }; diff --git a/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts b/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts index 5e9cf9f..efa575f 100644 --- a/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts +++ b/src/modules/ad/tests/unit/infrastructure/output-datetime-transformer.spec.ts @@ -29,6 +29,7 @@ const mockDefaultParamsProvider: DefaultParamsProviderPort = { AZIMUTH_MARGIN: 10, MAX_DETOUR_DISTANCE_RATIO: 0.3, MAX_DETOUR_DURATION_RATIO: 0.3, + PER_PAGE: 10, }; }, };