Files
gridpilot.gg/adapters/racing/persistence/media/InMemoryMediaRepository.ts
2025-12-31 15:39:28 +01:00

61 lines
1.7 KiB
TypeScript

/**
* Infrastructure Adapter: InMemoryMediaRepository
*
* In-memory implementation of IMediaRepository.
* Stores URLs for media assets like avatars and logos.
*/
import type { IMediaRepository } from '@core/racing/domain/repositories/IMediaRepository';
import type { Logger } from '@core/shared/application';
export class InMemoryMediaRepository implements IMediaRepository {
private driverAvatars = new Map<string, string>();
private teamLogos = new Map<string, string>();
private leagueLogos = new Map<string, string>();
private leagueCovers = new Map<string, string>();
constructor(private readonly logger: Logger) {
this.logger.info('[InMemoryMediaRepository] Initialized.');
}
async getDriverAvatar(driverId: string): Promise<string | null> {
return this.driverAvatars.get(driverId) ?? null;
}
async getTeamLogo(teamId: string): Promise<string | null> {
return this.teamLogos.get(teamId) ?? null;
}
async getLeagueLogo(leagueId: string): Promise<string | null> {
return this.leagueLogos.get(leagueId) ?? null;
}
async getLeagueCover(leagueId: string): Promise<string | null> {
return this.leagueCovers.get(leagueId) ?? null;
}
// Helper methods for seeding
setDriverAvatar(driverId: string, url: string): void {
this.driverAvatars.set(driverId, url);
}
setTeamLogo(teamId: string, url: string): void {
this.teamLogos.set(teamId, url);
}
setLeagueLogo(leagueId: string, url: string): void {
this.leagueLogos.set(leagueId, url);
}
setLeagueCover(leagueId: string, url: string): void {
this.leagueCovers.set(leagueId, url);
}
async clear(): Promise<void> {
this.driverAvatars.clear();
this.teamLogos.clear();
this.leagueLogos.clear();
this.leagueCovers.clear();
}
}