refactor to adapters

This commit is contained in:
2025-12-15 18:34:20 +01:00
parent fc671482c8
commit c817d76092
145 changed files with 906 additions and 361 deletions

View File

@@ -0,0 +1,16 @@
export interface RawStanding {
id: string;
leagueId: string;
driverId: string;
position: number;
points: number;
wins: number;
racesCompleted: number;
// These properties might be optional or present depending on the data source
seasonId?: string;
podiums?: number;
}
export interface ILeagueStandingsRepository {
getLeagueStandings(leagueId: string): Promise<RawStanding[]>;
}

View File

@@ -0,0 +1,20 @@
export interface GetLeagueStandingsUseCase {
execute(leagueId: string): Promise<LeagueStandingsViewModel>;
}
export interface StandingItemViewModel {
id: string;
leagueId: string;
seasonId: string;
driverId: string;
position: number;
points: number;
wins: number;
podiums: number;
racesCompleted: number;
}
export interface LeagueStandingsViewModel {
leagueId: string;
standings: StandingItemViewModel[];
}

View File

@@ -0,0 +1,29 @@
import { GetLeagueStandingsUseCase, LeagueStandingsViewModel, StandingItemViewModel } from './GetLeagueStandingsUseCase';
import { ILeagueStandingsRepository, RawStanding } from '../ports/ILeagueStandingsRepository';
export class GetLeagueStandingsUseCaseImpl implements GetLeagueStandingsUseCase {
constructor(private repository: ILeagueStandingsRepository) {}
async execute(leagueId: string): Promise<LeagueStandingsViewModel> {
const rawStandings = await this.repository.getLeagueStandings(leagueId);
const standingItems: StandingItemViewModel[] = rawStandings.map((standing: RawStanding) => {
return {
id: standing.id,
leagueId: standing.leagueId,
seasonId: standing.seasonId ?? '',
driverId: standing.driverId,
position: standing.position,
points: standing.points,
wins: standing.wins,
podiums: standing.podiums ?? 0,
racesCompleted: standing.racesCompleted,
};
});
return {
leagueId: leagueId,
standings: standingItems,
};
}
}