42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { Game } from '@core/racing/domain/entities/Game';
|
|
import { GameRepository } from '@core/racing/domain/repositories/GameRepository';
|
|
import { Logger } from '@core/shared/domain';
|
|
|
|
export class InMemoryGameRepository implements GameRepository {
|
|
private games: Map<string, Game> = new Map();
|
|
|
|
constructor(private readonly logger: Logger) {
|
|
this.logger.info('InMemoryGameRepository initialized.');
|
|
this.seedDefaults();
|
|
}
|
|
|
|
private seedDefaults(): void {
|
|
const defaults = [
|
|
Game.create({ id: 'iracing', name: 'iRacing' }),
|
|
Game.create({ id: 'acc', name: 'Assetto Corsa Competizione' }),
|
|
Game.create({ id: 'f1-24', name: 'F1 24' }),
|
|
Game.create({ id: 'f1-23', name: 'F1 23' }),
|
|
];
|
|
|
|
for (const game of defaults) {
|
|
this.games.set(game.id.toString(), game);
|
|
}
|
|
}
|
|
|
|
async findById(id: string): Promise<Game | null> {
|
|
this.logger.debug(`[InMemoryGameRepository] Finding game by ID: ${id}`);
|
|
const game = this.games.get(id) ?? null;
|
|
if (game) {
|
|
this.logger.info(`Found game by ID: ${id}.`);
|
|
} else {
|
|
this.logger.warn(`Game with ID ${id} not found.`);
|
|
}
|
|
return Promise.resolve(game);
|
|
}
|
|
|
|
async findAll(): Promise<Game[]> {
|
|
this.logger.debug('[InMemoryGameRepository] Finding all games.');
|
|
return Promise.resolve(Array.from(this.games.values()));
|
|
}
|
|
}
|