diff --git a/src/repositories/shuttle/RedisShuttleRepository.ts b/src/repositories/shuttle/RedisShuttleRepository.ts index f8da040..15c45a5 100644 --- a/src/repositories/shuttle/RedisShuttleRepository.ts +++ b/src/repositories/shuttle/RedisShuttleRepository.ts @@ -84,6 +84,11 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt return `shuttle:eta:historical:${routeId}:${fromStopId}:${toStopId}`; } + /** + * Represents a set storing the shuttles that are currently at a stop. + */ + private readonly shuttleIsAtStopKey = "shuttle:atstop"; + // Helper methods for converting entities to Redis hashes private createRedisHashFromStop = (stop: IStop): Record => ({ id: stop.id, @@ -409,10 +414,19 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt lastStopArrival: lastStop, willArriveAt: shuttleArrival, }); + await this.markShuttleAsAtStop(shuttleArrival.shuttleId); await this.updateShuttleLastStopArrival(shuttleArrival); } } + private async markShuttleAsAtStop(shuttleId: string) { + await this.redisClient.sAdd(this.shuttleIsAtStopKey, shuttleId); + } + + private async checkIfShuttleIsAtStop(shuttleId: string) { + return await this.redisClient.sIsMember(this.shuttleIsAtStopKey, shuttleId); + } + public async getAverageTravelTimeSeconds( { routeId, fromStopId, toStopId }: ShuttleTravelTimeDataIdentifier, { from, to }: ShuttleTravelTimeDateFilterArguments,