mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
update InterchangeSystem build methods to attach parking system
This commit is contained in:
@@ -7,6 +7,12 @@ import { ShuttleGetterSetterRepository } from "../repositories/ShuttleGetterSett
|
||||
import { InMemoryNotificationRepository } from "../repositories/InMemoryNotificationRepository";
|
||||
import { AppleNotificationSender } from "../notifications/senders/AppleNotificationSender";
|
||||
import { ApiBasedShuttleRepositoryLoader } from "../loaders/shuttle/ApiBasedShuttleRepositoryLoader";
|
||||
import { ParkingGetterSetterRepository } from "../repositories/ParkingGetterSetterRepository";
|
||||
import { InMemoryParkingRepository } from "../repositories/InMemoryParkingRepository";
|
||||
import {
|
||||
buildParkingRepositoryLoaderIfExists,
|
||||
ParkingRepositoryLoaderBuilderArguments
|
||||
} from "../loaders/parking/buildParkingRepositoryLoaderIfExists";
|
||||
|
||||
export interface InterchangeSystemBuilderArguments {
|
||||
name: string;
|
||||
@@ -20,16 +26,23 @@ export interface InterchangeSystemBuilderArguments {
|
||||
* ID for fetching shuttle data from the Passio GO! system.
|
||||
*/
|
||||
passioSystemId: string;
|
||||
|
||||
/**
|
||||
* ID for the parking repository ID in the codebase.
|
||||
*/
|
||||
parkingSystemId?: string;
|
||||
}
|
||||
|
||||
export class InterchangeSystem {
|
||||
constructor(
|
||||
private constructor(
|
||||
public name: string,
|
||||
public id: string,
|
||||
public shuttleTimedDataLoader: TimedApiBasedRepositoryLoader,
|
||||
public shuttleRepository: ShuttleGetterSetterRepository,
|
||||
public notificationScheduler: ETANotificationScheduler,
|
||||
public notificationRepository: NotificationRepository,
|
||||
public parkingTimedDataLoader: TimedApiBasedRepositoryLoader | null,
|
||||
public parkingRepository: ParkingGetterSetterRepository | null,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -61,6 +74,9 @@ export class InterchangeSystem {
|
||||
);
|
||||
notificationScheduler.startListeningForUpdates();
|
||||
|
||||
let { parkingRepository, timedParkingLoader } = this.buildParkingLoaderAndRepository(args.parkingSystemId);
|
||||
timedParkingLoader?.start();
|
||||
|
||||
return new InterchangeSystem(
|
||||
args.name,
|
||||
args.id,
|
||||
@@ -68,6 +84,8 @@ export class InterchangeSystem {
|
||||
shuttleRepository,
|
||||
notificationScheduler,
|
||||
notificationRepository,
|
||||
timedParkingLoader,
|
||||
parkingRepository,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -100,6 +118,9 @@ export class InterchangeSystem {
|
||||
);
|
||||
notificationScheduler.startListeningForUpdates();
|
||||
|
||||
let { parkingRepository, timedParkingLoader } = this.buildParkingLoaderAndRepository(args.parkingSystemId);
|
||||
// Timed parking loader is not started
|
||||
|
||||
return new InterchangeSystem(
|
||||
args.name,
|
||||
args.id,
|
||||
@@ -107,6 +128,32 @@ export class InterchangeSystem {
|
||||
shuttleRepository,
|
||||
notificationScheduler,
|
||||
notificationRepository,
|
||||
timedParkingLoader,
|
||||
parkingRepository,
|
||||
);
|
||||
}
|
||||
|
||||
private static buildParkingLoaderAndRepository(id?: string) {
|
||||
if (id === undefined) {
|
||||
return { parkingRepository: null, timedParkingLoader: null };
|
||||
}
|
||||
|
||||
let parkingRepository: ParkingGetterSetterRepository | null = new InMemoryParkingRepository();
|
||||
const loaderBuilderArguments: ParkingRepositoryLoaderBuilderArguments = {
|
||||
id,
|
||||
repository: parkingRepository,
|
||||
};
|
||||
let parkingLoader = buildParkingRepositoryLoaderIfExists(
|
||||
loaderBuilderArguments,
|
||||
);
|
||||
|
||||
let timedParkingLoader = null;
|
||||
if (parkingLoader == null) {
|
||||
parkingRepository = null;
|
||||
} else {
|
||||
timedParkingLoader = new TimedApiBasedRepositoryLoader(parkingLoader);
|
||||
}
|
||||
return { parkingRepository, timedParkingLoader };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user