add repository interface

This commit is contained in:
2024-12-22 13:58:31 -08:00
parent 1a69f9faf8
commit b43666b956

86
src/repository.ts Normal file
View File

@@ -0,0 +1,86 @@
// If types match closely, we can use TypeScript "casting"
// to convert from data repo to GraphQL schema
export interface ISystem {
id: string;
name: string;
}
export interface ICoordinates {
latitude: number;
longitude: number;
}
export interface IRoute {
id: string;
name: string;
color: string;
polylineCoordinates: ICoordinates[];
systemId: string;
}
export interface IStop {
id: string;
name: string;
systemId: string;
coordinates: ICoordinates;
}
export interface IShuttle {
coordinates: ICoordinates;
id: string;
name: string;
routeId: string;
systemId: string;
}
export interface IEta {
secondsRemaining: number;
shuttleId: string;
stopId: string;
}
export interface IOrderedStop {
nextStopId: string;
previousStopId: string;
routeId: string;
stopId: string;
}
/**
* Repository interface for data derived from Passio API.
* The repository is not designed to have write locks in place.
*/
export interface Repository {
// Getter methods
getSystems(): Promise<ISystem[]>;
getSystemById(systemId: string): Promise<ISystem>;
getStopsBySystemId(systemId: string): Promise<IStop[]>;
getStopById(stopId: string): Promise<IStop[]>;
getRoutesBySystemId(systemId: string): Promise<IRoute[]>;
getRouteById(routeId: string): Promise<IRoute>;
getShuttlesBySystemId(systemId: string): Promise<IShuttle[]>;
getShuttleById(shuttleId: string): Promise<IShuttle[]>;
getEtasForShuttleId(shuttleId: string): Promise<IEta[]>;
getEtasForStopId(stopId: string): Promise<IEta[]>;
getEtaForShuttleAndStopId(shuttleId: string, stopId: string): Promise<IEta[]>;
getOrderedStopByRouteAndStopId(routeId: string, stopId: string): Promise<IOrderedStop[]>;
getOrderedStopsByStopId(stopId: string): Promise<IOrderedStop[]>;
getOrderedStopsByRouteId(routeId: string): Promise<IOrderedStop[]>;
getNextOrderedStopFromOrderedStopId(stopId: string): Promise<IOrderedStop | null>;
getPreviousOrderedStopFromOrderedStopId(stopId: string): Promise<IOrderedStop | null>;
// Setter methods
addOrUpdateSystem(system: ISystem): Promise<void>;
addOrUpdateRoute(route: IRoute): Promise<void>;
addOrUpdateShuttle(shuttle: IShuttle): Promise<void>;
addOrUpdateStop(stop: IStop): Promise<void>;
addOrUpdateOrderedStop(orderedStop: IStop): Promise<void>;
addOrUpdateEta(eta: IEta): Promise<void>;
}