module creation
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { ILeagueStandingsRepository, RawStanding } from '@gridpilot/core/league/application/ports/ILeagueStandingsRepository';
|
||||
import { ILogger } from '@gridpilot/shared/logging/ILogger';
|
||||
|
||||
export class InMemoryLeagueStandingsRepository implements ILeagueStandingsRepository {
|
||||
private standings: Map<string, RawStanding[]> = new Map(); // Key: leagueId
|
||||
|
||||
constructor(private readonly logger: ILogger, 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}.`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user