Files
gridpilot.gg/adapters/racing/persistence/inmemory/InMemoryLeagueStandingsRepository.ts
2025-12-16 13:13:03 +01:00

31 lines
1.5 KiB
TypeScript

import { ILeagueStandingsRepository, RawStanding } from '@core/league/application/ports/ILeagueStandingsRepository';
import { Logger } from '@core/shared/application';
export class InMemoryLeagueStandingsRepository implements ILeagueStandingsRepository {
private standings: Map<string, RawStanding[]> = new Map(); // Key: leagueId
constructor(private readonly logger: Logger, initialStandings: Record<string, RawStanding[]> = {}) {
this.logger.info('InMemoryLeagueStandingsRepository initialized.');
for (const leagueId in initialStandings) {
// Ensure initialStandings[leagueId] is not undefined before setting
if (initialStandings[leagueId] !== undefined) {
this.standings.set(leagueId, initialStandings[leagueId]);
this.logger.debug(`Seeded standings for league: ${leagueId}.`);
}
}
}
async getLeagueStandings(leagueId: string): Promise<RawStanding[]> {
this.logger.debug(`[InMemoryLeagueStandingsRepository] Getting standings for league: ${leagueId}.`);
const leagueStandings = this.standings.get(leagueId) ?? [];
this.logger.info(`Found ${leagueStandings.length} standings for league: ${leagueId}.`);
return Promise.resolve(leagueStandings);
}
// Helper method for seeding/updating if needed by other in-memory repos
public setLeagueStandings(leagueId: string, standings: RawStanding[]): void {
this.standings.set(leagueId, standings);
this.logger.debug(`[InMemoryLeagueStandingsRepository] Set standings for league: ${leagueId}.`);
}
}