Files
gridpilot.gg/adapters/leaderboards/persistence/inmemory/InMemoryLeaderboardsRepository.ts
Marc Mintel 597bb48248
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 4m51s
Contract Testing / contract-snapshot (pull_request) Has been skipped
integration tests
2026-01-22 17:29:06 +01:00

45 lines
1.2 KiB
TypeScript

/**
* Infrastructure Adapter: InMemoryLeaderboardsRepository
*
* In-memory implementation of LeaderboardsRepository.
* Stores data in a Map structure.
*/
import {
LeaderboardsRepository,
LeaderboardDriverData,
LeaderboardTeamData,
} from '../../../../core/leaderboards/application/ports/LeaderboardsRepository';
export class InMemoryLeaderboardsRepository implements LeaderboardsRepository {
private drivers: Map<string, LeaderboardDriverData> = new Map();
private teams: Map<string, LeaderboardTeamData> = new Map();
async findAllDrivers(): Promise<LeaderboardDriverData[]> {
return Array.from(this.drivers.values());
}
async findAllTeams(): Promise<LeaderboardTeamData[]> {
return Array.from(this.teams.values());
}
async findDriversByTeamId(teamId: string): Promise<LeaderboardDriverData[]> {
return Array.from(this.drivers.values()).filter(
(driver) => driver.teamId === teamId,
);
}
addDriver(driver: LeaderboardDriverData): void {
this.drivers.set(driver.id, driver);
}
addTeam(team: LeaderboardTeamData): void {
this.teams.set(team.id, team);
}
clear(): void {
this.drivers.clear();
this.teams.clear();
}
}