From 17b6f93f0e6634f84d38cb93492f6821e38bc16d Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 8 Jan 2025 16:44:06 -0800 Subject: [PATCH] add implementation for getEtasForStopId and getEtasForShuttleId --- src/repositories/ApiBasedRepository.ts | 33 ++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/repositories/ApiBasedRepository.ts b/src/repositories/ApiBasedRepository.ts index 5eb963e..b7d5cc0 100644 --- a/src/repositories/ApiBasedRepository.ts +++ b/src/repositories/ApiBasedRepository.ts @@ -84,12 +84,34 @@ export class ApiBasedRepository implements GetterRepository { return null; } - public async getEtasForShuttleId(shuttleId: string): Promise<[]> { - return []; + public async getEtasForShuttleId(shuttleId: string): Promise { + const shuttle = await this.getShuttleById(shuttleId); + const systemId = shuttle?.systemId; + if (!systemId) { + return []; + } + await this.updateEtasForSystemIfTTL(systemId); + + if (!this.cache?.etasForShuttleId || !this.cache.etasForShuttleId[shuttleId]) { + return []; + } + + return this.cache.etasForShuttleId[shuttleId]; } - public async getEtasForStopId(stopId: string): Promise<[]> { - return []; + public async getEtasForStopId(stopId: string): Promise { + const stop = await this.getStopById(stopId); + const systemId = stop?.systemId; + if (!systemId) { + return []; + } + await this.updateEtasForSystemIfTTL(systemId); + + if (!this.cache?.etasForStopId || !this.cache.etasForStopId[stopId]) { + return []; + } + + return this.cache.etasForStopId[stopId]; } public async updateEtasForSystemIfTTL(systemId: string) { @@ -262,7 +284,8 @@ ${json}`); } } - public async getStopById(stopId: string): Promise<| null> { + public async getStopById(stopId: string): Promise { + // TODO: implement return null; }