mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +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"
|
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 {
|
export interface ApiBasedRepositoryCache {
|
||||||
etasForShuttleId?: {
|
etasForShuttleId?: {
|
||||||
[shuttleId: string]: IEta[],
|
[shuttleId: string]: IEta[],
|
||||||
@@ -13,6 +17,9 @@ export interface ApiBasedRepositoryCache {
|
|||||||
stopsBySystemId?: {
|
stopsBySystemId?: {
|
||||||
[systemId: string]: IStop[],
|
[systemId: string]: IStop[],
|
||||||
},
|
},
|
||||||
|
stopByStopId?: {
|
||||||
|
[stopId: string]: IStop,
|
||||||
|
},
|
||||||
shuttleByShuttleId?: {
|
shuttleByShuttleId?: {
|
||||||
[shuttleId: string]: IShuttle,
|
[shuttleId: string]: IShuttle,
|
||||||
},
|
},
|
||||||
@@ -115,6 +122,7 @@ export class ApiBasedRepository implements GetterRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateEtasForSystemIfTTL(systemId: string) {
|
public async updateEtasForSystemIfTTL(systemId: string) {
|
||||||
|
// TODO: check if TTL
|
||||||
try {
|
try {
|
||||||
const stops = await this.getStopsBySystemId(systemId);
|
const stops = await this.getStopsBySystemId(systemId);
|
||||||
await Promise.all(stops.map(async (stop) => {
|
await Promise.all(stops.map(async (stop) => {
|
||||||
@@ -224,6 +232,7 @@ export class ApiBasedRepository implements GetterRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async updateShuttlesForSystemIfTTL(systemId: string) {
|
public async updateShuttlesForSystemIfTTL(systemId: string) {
|
||||||
|
// TODO: check if TTL
|
||||||
try {
|
try {
|
||||||
// TODO: update shuttlesByRouteId
|
// TODO: update shuttlesByRouteId
|
||||||
// Update shuttleByShuttleId, shuttlesBySystemId
|
// Update shuttleByShuttleId, shuttlesBySystemId
|
||||||
@@ -285,12 +294,20 @@ ${json}`);
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getStopById(stopId: string): Promise<IStop | null> {
|
public async getStopById(stopId: string): Promise<IStop | null> {
|
||||||
// TODO: implement
|
if (!this.cache.stopByStopId) return null;
|
||||||
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[]> {
|
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
|
||||||
await this.updateStopsForSystemId(systemId);
|
await this.updateStopsForSystemIdIfTTL(systemId);
|
||||||
|
|
||||||
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
|
if (!this.cache.stopsBySystemId || this.cache.stopsBySystemId[systemId]) {
|
||||||
return [];
|
return [];
|
||||||
@@ -298,7 +315,9 @@ ${json}`);
|
|||||||
return this.cache.stopsBySystemId[systemId];
|
return this.cache.stopsBySystemId[systemId];
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateStopsForSystemId(systemId: string) {
|
public async updateStopsForSystemIdIfTTL(systemId: string) {
|
||||||
|
// TODO: check if TTL
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = {
|
const params = {
|
||||||
getStops: "2",
|
getStops: "2",
|
||||||
|
|||||||
Reference in New Issue
Block a user