update InterchangeSystem build methods to attach parking system

This commit is contained in:
2025-04-16 16:22:01 -07:00
parent 6f6bab7058
commit 267da3ff36
2 changed files with 50 additions and 3 deletions

View File

@@ -7,6 +7,12 @@ import { ShuttleGetterSetterRepository } from "../repositories/ShuttleGetterSett
import { InMemoryNotificationRepository } from "../repositories/InMemoryNotificationRepository"; import { InMemoryNotificationRepository } from "../repositories/InMemoryNotificationRepository";
import { AppleNotificationSender } from "../notifications/senders/AppleNotificationSender"; import { AppleNotificationSender } from "../notifications/senders/AppleNotificationSender";
import { ApiBasedShuttleRepositoryLoader } from "../loaders/shuttle/ApiBasedShuttleRepositoryLoader"; 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 { export interface InterchangeSystemBuilderArguments {
name: string; name: string;
@@ -20,16 +26,23 @@ export interface InterchangeSystemBuilderArguments {
* ID for fetching shuttle data from the Passio GO! system. * ID for fetching shuttle data from the Passio GO! system.
*/ */
passioSystemId: string; passioSystemId: string;
/**
* ID for the parking repository ID in the codebase.
*/
parkingSystemId?: string;
} }
export class InterchangeSystem { export class InterchangeSystem {
constructor( private constructor(
public name: string, public name: string,
public id: string, public id: string,
public shuttleTimedDataLoader: TimedApiBasedRepositoryLoader, public shuttleTimedDataLoader: TimedApiBasedRepositoryLoader,
public shuttleRepository: ShuttleGetterSetterRepository, public shuttleRepository: ShuttleGetterSetterRepository,
public notificationScheduler: ETANotificationScheduler, public notificationScheduler: ETANotificationScheduler,
public notificationRepository: NotificationRepository, public notificationRepository: NotificationRepository,
public parkingTimedDataLoader: TimedApiBasedRepositoryLoader | null,
public parkingRepository: ParkingGetterSetterRepository | null,
) { ) {
} }
@@ -61,6 +74,9 @@ export class InterchangeSystem {
); );
notificationScheduler.startListeningForUpdates(); notificationScheduler.startListeningForUpdates();
let { parkingRepository, timedParkingLoader } = this.buildParkingLoaderAndRepository(args.parkingSystemId);
timedParkingLoader?.start();
return new InterchangeSystem( return new InterchangeSystem(
args.name, args.name,
args.id, args.id,
@@ -68,6 +84,8 @@ export class InterchangeSystem {
shuttleRepository, shuttleRepository,
notificationScheduler, notificationScheduler,
notificationRepository, notificationRepository,
timedParkingLoader,
parkingRepository,
); );
} }
@@ -100,6 +118,9 @@ export class InterchangeSystem {
); );
notificationScheduler.startListeningForUpdates(); notificationScheduler.startListeningForUpdates();
let { parkingRepository, timedParkingLoader } = this.buildParkingLoaderAndRepository(args.parkingSystemId);
// Timed parking loader is not started
return new InterchangeSystem( return new InterchangeSystem(
args.name, args.name,
args.id, args.id,
@@ -107,6 +128,32 @@ export class InterchangeSystem {
shuttleRepository, shuttleRepository,
notificationScheduler, notificationScheduler,
notificationRepository, 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 };
}
} }

View File

@@ -1,12 +1,12 @@
import { ParkingGetterSetterRepository } from "../../repositories/ParkingGetterSetterRepository"; import { ParkingGetterSetterRepository } from "../../repositories/ParkingGetterSetterRepository";
import { ChapmanApiBasedParkingRepositoryLoader } from "./ChapmanApiBasedParkingRepositoryLoader"; import { ChapmanApiBasedParkingRepositoryLoader } from "./ChapmanApiBasedParkingRepositoryLoader";
interface ParkingRepositoryBuilderArguments { export interface ParkingRepositoryLoaderBuilderArguments {
id: string; id: string;
repository: ParkingGetterSetterRepository; repository: ParkingGetterSetterRepository;
} }
export function buildParkingRepositoryLoaderIfExists(args: ParkingRepositoryBuilderArguments) { export function buildParkingRepositoryLoaderIfExists(args: ParkingRepositoryLoaderBuilderArguments) {
if (args.id === ChapmanApiBasedParkingRepositoryLoader.id) { if (args.id === ChapmanApiBasedParkingRepositoryLoader.id) {
return new ChapmanApiBasedParkingRepositoryLoader(args.repository); return new ChapmanApiBasedParkingRepositoryLoader(args.repository);
} }