mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
implemnet getStopById method
This commit is contained in:
@@ -3,6 +3,10 @@ import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entitie
|
||||
|
||||
const baseUrl = "https://passiogo.com/mapGetData.php"
|
||||
|
||||
// TODO: add TTL values to everything
|
||||
// TODO: remove RepositoryDataLoader and UnoptimizedInMemoryRepository
|
||||
// TODO: make milleseconds (TTL) required on everything
|
||||
|
||||
export interface ApiBasedRepositoryCache {
|
||||
etasForShuttleId?: {
|
||||
[shuttleId: string]: IEta[],
|
||||
@@ -13,6 +17,9 @@ export interface ApiBasedRepositoryCache {
|
||||
stopsBySystemId?: {
|
||||
[systemId: string]: IStop[],
|
||||
},
|
||||
stopByStopId?: {
|
||||
[stopId: string]: IStop,
|
||||
},
|
||||
shuttleByShuttleId?: {
|
||||
[shuttleId: string]: IShuttle,
|
||||
},
|
||||
@@ -115,6 +122,7 @@ export class ApiBasedRepository implements GetterRepository {
|
||||
}
|
||||
|
||||
public async updateEtasForSystemIfTTL(systemId: string) {
|
||||
// TODO: check if TTL
|
||||
try {
|
||||
const stops = await this.getStopsBySystemId(systemId);
|
||||
await Promise.all(stops.map(async (stop) => {
|
||||
@@ -224,6 +232,7 @@ export class ApiBasedRepository implements GetterRepository {
|
||||
}
|
||||
|
||||
public async updateShuttlesForSystemIfTTL(systemId: string) {
|
||||
// TODO: check if TTL
|
||||
try {
|
||||
// TODO: update shuttlesByRouteId
|
||||
// Update shuttleByShuttleId, shuttlesBySystemId
|
||||
@@ -285,12 +294,20 @@ ${json}`);
|
||||
}
|
||||
|
||||
public async getStopById(stopId: string): Promise<IStop | null> {
|
||||
// TODO: implement
|
||||
return null;
|
||||
if (!this.cache.stopByStopId) return null;
|
||||
const oldStop = this.cache.stopByStopId[stopId];
|
||||
if (!oldStop) return null;
|
||||
|
||||
await this.updateStopsForSystemIdIfTTL(oldStop.systemId);
|
||||
|
||||
const newStop = this.cache.stopByStopId[stopId];
|
||||
if (!newStop) return null;
|
||||
|
||||
return newStop;
|
||||
}
|
||||
|
||||
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
|
||||
await this.updateStopsForSystemId(systemId);
|
||||
await this.updateStopsForSystemIdIfTTL(systemId);
|
||||
|
||||
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
|
||||
return [];
|
||||
@@ -298,7 +315,9 @@ ${json}`);
|
||||
return this.cache.stopsBySystemId[systemId];
|
||||
}
|
||||
|
||||
public async updateStopsForSystemId(systemId: string) {
|
||||
public async updateStopsForSystemIdIfTTL(systemId: string) {
|
||||
// TODO: check if TTL
|
||||
|
||||
try {
|
||||
const params = {
|
||||
getStops: "2",
|
||||
|
||||
Reference in New Issue
Block a user