mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Update InterchangeSystem builder to use Redis-based shuttle repository
This commit is contained in:
@@ -14,6 +14,8 @@ import {
|
|||||||
ParkingRepositoryLoaderBuilderArguments
|
ParkingRepositoryLoaderBuilderArguments
|
||||||
} from "../loaders/parking/buildParkingRepositoryLoaderIfExists";
|
} from "../loaders/parking/buildParkingRepositoryLoaderIfExists";
|
||||||
import { RedisParkingRepository } from "../repositories/parking/RedisParkingRepository";
|
import { RedisParkingRepository } from "../repositories/parking/RedisParkingRepository";
|
||||||
|
import { RedisShuttleRepository } from "../repositories/shuttle/RedisShuttleRepository";
|
||||||
|
import { ShuttleGetterRepository } from "../repositories/shuttle/ShuttleGetterRepository";
|
||||||
|
|
||||||
export interface InterchangeSystemBuilderArguments {
|
export interface InterchangeSystemBuilderArguments {
|
||||||
name: string;
|
name: string;
|
||||||
@@ -55,28 +57,13 @@ export class InterchangeSystem {
|
|||||||
static async build(
|
static async build(
|
||||||
args: InterchangeSystemBuilderArguments,
|
args: InterchangeSystemBuilderArguments,
|
||||||
) {
|
) {
|
||||||
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
const { shuttleRepository, timedShuttleDataLoader } = await InterchangeSystem.buildRedisShuttleLoaderAndRepository(args);
|
||||||
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
timedShuttleDataLoader.start();
|
||||||
args.passioSystemId,
|
|
||||||
args.id,
|
|
||||||
shuttleRepository
|
|
||||||
);
|
|
||||||
const timedShuttleDataLoader = new TimedApiBasedRepositoryLoader(
|
|
||||||
shuttleDataLoader,
|
|
||||||
);
|
|
||||||
await timedShuttleDataLoader.start();
|
|
||||||
|
|
||||||
const notificationRepository = new RedisNotificationRepository();
|
const { notificationScheduler, notificationRepository } = await InterchangeSystem.buildNotificationSchedulerAndRepository(shuttleRepository, args);
|
||||||
await notificationRepository.connect();
|
|
||||||
const notificationScheduler = new ETANotificationScheduler(
|
|
||||||
shuttleRepository,
|
|
||||||
notificationRepository,
|
|
||||||
new AppleNotificationSender(),
|
|
||||||
args.id,
|
|
||||||
);
|
|
||||||
notificationScheduler.startListeningForUpdates();
|
notificationScheduler.startListeningForUpdates();
|
||||||
|
|
||||||
let { parkingRepository, timedParkingLoader } = await this.buildRedisParkingLoaderAndRepository(args.parkingSystemId);
|
let { parkingRepository, timedParkingLoader } = await InterchangeSystem.buildRedisParkingLoaderAndRepository(args.parkingSystemId);
|
||||||
timedParkingLoader?.start();
|
timedParkingLoader?.start();
|
||||||
|
|
||||||
return new InterchangeSystem(
|
return new InterchangeSystem(
|
||||||
@@ -91,49 +78,30 @@ export class InterchangeSystem {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static async buildRedisShuttleLoaderAndRepository(args: InterchangeSystemBuilderArguments) {
|
||||||
* Construct an instance of the class where all composited
|
const shuttleRepository = new RedisShuttleRepository();
|
||||||
* classes are correctly linked, meant for unit tests, and server/app
|
await shuttleRepository.connect();
|
||||||
* integration tests.
|
|
||||||
* @param args
|
|
||||||
*/
|
|
||||||
static buildForTesting(
|
|
||||||
args: InterchangeSystemBuilderArguments,
|
|
||||||
) {
|
|
||||||
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
|
||||||
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
||||||
args.passioSystemId,
|
args.passioSystemId,
|
||||||
args.id,
|
args.id,
|
||||||
shuttleRepository
|
shuttleRepository
|
||||||
);
|
);
|
||||||
// Note that this loader should not be started,
|
const timedShuttleDataLoader = new TimedApiBasedRepositoryLoader(
|
||||||
// so the test data doesn't get overwritten
|
shuttleDataLoader
|
||||||
const timedShuttleLoader = new TimedApiBasedRepositoryLoader(
|
|
||||||
shuttleDataLoader,
|
|
||||||
);
|
);
|
||||||
|
return { shuttleRepository, timedShuttleDataLoader };
|
||||||
|
}
|
||||||
|
|
||||||
const notificationRepository = new InMemoryNotificationRepository();
|
private static async buildNotificationSchedulerAndRepository(shuttleRepository: ShuttleGetterRepository, args: InterchangeSystemBuilderArguments) {
|
||||||
|
const notificationRepository = new RedisNotificationRepository();
|
||||||
|
await notificationRepository.connect();
|
||||||
const notificationScheduler = new ETANotificationScheduler(
|
const notificationScheduler = new ETANotificationScheduler(
|
||||||
shuttleRepository,
|
shuttleRepository,
|
||||||
notificationRepository,
|
notificationRepository,
|
||||||
new AppleNotificationSender(false),
|
new AppleNotificationSender(),
|
||||||
args.id,
|
args.id
|
||||||
);
|
|
||||||
notificationScheduler.startListeningForUpdates();
|
|
||||||
|
|
||||||
let { parkingRepository, timedParkingLoader } = this.buildInMemoryParkingLoaderAndRepository(args.parkingSystemId);
|
|
||||||
// Timed parking loader is not started here
|
|
||||||
|
|
||||||
return new InterchangeSystem(
|
|
||||||
args.name,
|
|
||||||
args.id,
|
|
||||||
timedShuttleLoader,
|
|
||||||
shuttleRepository,
|
|
||||||
notificationScheduler,
|
|
||||||
notificationRepository,
|
|
||||||
timedParkingLoader,
|
|
||||||
parkingRepository,
|
|
||||||
);
|
);
|
||||||
|
return { notificationScheduler, notificationRepository };
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async buildRedisParkingLoaderAndRepository(id?: string) {
|
private static async buildRedisParkingLoaderAndRepository(id?: string) {
|
||||||
@@ -161,6 +129,47 @@ export class InterchangeSystem {
|
|||||||
return { parkingRepository, timedParkingLoader };
|
return { parkingRepository, timedParkingLoader };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct an instance of the class where all composited
|
||||||
|
* classes are correctly linked, meant for unit tests, and server/app
|
||||||
|
* integration tests.
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
static buildForTesting(
|
||||||
|
args: InterchangeSystemBuilderArguments,
|
||||||
|
) {
|
||||||
|
const { shuttleRepository, timedShuttleLoader } = InterchangeSystem.buildInMemoryShuttleLoaderAndRepository(args);
|
||||||
|
// Timed shuttle loader is not started here
|
||||||
|
|
||||||
|
const { notificationScheduler, notificationRepository } = InterchangeSystem.buildInMemoryNotificationSchedulerAndRepository(shuttleRepository, args);
|
||||||
|
notificationScheduler.startListeningForUpdates();
|
||||||
|
|
||||||
|
let { parkingRepository, timedParkingLoader } = this.buildInMemoryParkingLoaderAndRepository(args.parkingSystemId);
|
||||||
|
// Timed parking loader is not started here
|
||||||
|
|
||||||
|
return new InterchangeSystem(
|
||||||
|
args.name,
|
||||||
|
args.id,
|
||||||
|
timedShuttleLoader,
|
||||||
|
shuttleRepository,
|
||||||
|
notificationScheduler,
|
||||||
|
notificationRepository,
|
||||||
|
timedParkingLoader,
|
||||||
|
parkingRepository,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static buildInMemoryNotificationSchedulerAndRepository(shuttleRepository: UnoptimizedInMemoryShuttleRepository, args: InterchangeSystemBuilderArguments) {
|
||||||
|
const notificationRepository = new InMemoryNotificationRepository();
|
||||||
|
const notificationScheduler = new ETANotificationScheduler(
|
||||||
|
shuttleRepository,
|
||||||
|
notificationRepository,
|
||||||
|
new AppleNotificationSender(false),
|
||||||
|
args.id
|
||||||
|
);
|
||||||
|
return { notificationScheduler, notificationRepository };
|
||||||
|
}
|
||||||
|
|
||||||
private static buildInMemoryParkingLoaderAndRepository(id?: string) {
|
private static buildInMemoryParkingLoaderAndRepository(id?: string) {
|
||||||
if (id === undefined) {
|
if (id === undefined) {
|
||||||
return { parkingRepository: null, timedParkingLoader: null };
|
return { parkingRepository: null, timedParkingLoader: null };
|
||||||
@@ -184,4 +193,19 @@ export class InterchangeSystem {
|
|||||||
return { parkingRepository, timedParkingLoader };
|
return { parkingRepository, timedParkingLoader };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static buildInMemoryShuttleLoaderAndRepository(args: InterchangeSystemBuilderArguments) {
|
||||||
|
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
|
||||||
|
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
|
||||||
|
args.passioSystemId,
|
||||||
|
args.id,
|
||||||
|
shuttleRepository
|
||||||
|
);
|
||||||
|
// Note that this loader should not be started,
|
||||||
|
// so the test data doesn't get overwritten
|
||||||
|
const timedShuttleLoader = new TimedApiBasedRepositoryLoader(
|
||||||
|
shuttleDataLoader
|
||||||
|
);
|
||||||
|
return { shuttleRepository, timedShuttleLoader };
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user