mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
106 lines
2.6 KiB
TypeScript
106 lines
2.6 KiB
TypeScript
import { GetterRepository } from "./GetterRepository";
|
|
import { IEta, IOrderedStop, IRoute, IShuttle, IStop } from "../entities/entities";
|
|
|
|
export interface ApiBasedRepositoryCache {
|
|
etasForShuttleId?: {
|
|
[shuttleId: string]: IEta[],
|
|
},
|
|
etasForStopId?: {
|
|
[stopId: string]: IEta[],
|
|
},
|
|
stopsBySystemId?: {
|
|
[systemId: string]: IStop[],
|
|
},
|
|
shuttlesByShuttleId?: {
|
|
[shuttleId: string]: IShuttle[],
|
|
},
|
|
// To speed things up, implement caches for other data later
|
|
}
|
|
|
|
export interface ApiBasedRepositoryMillisecondTTLs {
|
|
etasForShuttleId: number,
|
|
etasForStopId: number,
|
|
}
|
|
|
|
const emptyCache: ApiBasedRepositoryCache = {
|
|
etasForShuttleId: {},
|
|
etasForStopId: {},
|
|
}
|
|
|
|
const defaultTtls: ApiBasedRepositoryMillisecondTTLs = {
|
|
etasForShuttleId: 10000,
|
|
etasForStopId: 10000,
|
|
}
|
|
|
|
export class ApiBasedRepository implements GetterRepository {
|
|
constructor(
|
|
private initialCache: ApiBasedRepositoryCache | undefined = emptyCache,
|
|
private ttls: ApiBasedRepositoryMillisecondTTLs = defaultTtls,
|
|
) {
|
|
}
|
|
|
|
public async getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta | null> {
|
|
return null;
|
|
}
|
|
|
|
public async getEtasForShuttleId(shuttleId: string): Promise<[]> {
|
|
return [];
|
|
}
|
|
|
|
public async getEtasForStopId(stopId: string): Promise<[]> {
|
|
return [];
|
|
}
|
|
|
|
public async updateEtasForSystemIfTTL(systemId: string) {
|
|
|
|
}
|
|
|
|
// TODO: migrate rest of logic over to this class
|
|
public async getOrderedStopByRouteAndStopId(routeId: string, stopId: string): Promise<| null> {
|
|
return null;
|
|
}
|
|
|
|
public async getOrderedStopsByRouteId(routeId: string): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
public async getOrderedStopsByStopId(stopId: string): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
public async getRouteById(routeId: string): Promise<| null> {
|
|
return Promise.resolve(null);
|
|
}
|
|
|
|
public async getRoutesBySystemId(systemId: string): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
public async getShuttleById(shuttleId: string): Promise<| null> {
|
|
return Promise.resolve(null);
|
|
}
|
|
|
|
public async getShuttlesByRouteId(routeId: string): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
public async getShuttlesBySystemId(systemId: string): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
|
|
public async getStopById(stopId: string): Promise<| null> {
|
|
return null;
|
|
}
|
|
|
|
public async getStopsBySystemId(systemId: string): Promise<IStop[]> {
|
|
return [];
|
|
}
|
|
|
|
public async getSystemById(systemId: string): Promise<| null> {
|
|
return null;
|
|
}
|
|
|
|
public async getSystems(): Promise<[]> {
|
|
return Promise.resolve([]);
|
|
}
|
|
} |