refactor to adapters
This commit is contained in:
16
core/league/application/ports/ILeagueStandingsRepository.ts
Normal file
16
core/league/application/ports/ILeagueStandingsRepository.ts
Normal 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[]>;
|
||||
}
|
||||
@@ -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[];
|
||||
}
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user