refactor to adapters
This commit is contained in:
@@ -1,41 +1,22 @@
|
||||
import type {
|
||||
ILeagueStandingsPresenter,
|
||||
LeagueStandingsResultDTO,
|
||||
LeagueStandingsViewModel,
|
||||
StandingItemViewModel,
|
||||
} from '@gridpilot/racing/application/presenters/ILeagueStandingsPresenter';
|
||||
import { GetLeagueStandingsUseCase, LeagueStandingsViewModel } from '@gridpilot/core/league/application/use-cases/GetLeagueStandingsUseCase';
|
||||
|
||||
export interface ILeagueStandingsPresenter {
|
||||
present(leagueId: string): Promise<void>;
|
||||
getViewModel(): LeagueStandingsViewModel | null;
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
export class LeagueStandingsPresenter implements ILeagueStandingsPresenter {
|
||||
private viewModel: LeagueStandingsViewModel | null = null;
|
||||
|
||||
constructor(private getLeagueStandingsUseCase: GetLeagueStandingsUseCase) {}
|
||||
|
||||
reset(): void {
|
||||
this.viewModel = null;
|
||||
}
|
||||
|
||||
present(dto: LeagueStandingsResultDTO): void {
|
||||
const standingItems: StandingItemViewModel[] = dto.standings.map((standing) => {
|
||||
const raw = standing as unknown as {
|
||||
seasonId?: string;
|
||||
podiums?: number;
|
||||
};
|
||||
|
||||
return {
|
||||
id: standing.id,
|
||||
leagueId: standing.leagueId,
|
||||
seasonId: raw.seasonId ?? '',
|
||||
driverId: standing.driverId,
|
||||
position: standing.position,
|
||||
points: standing.points,
|
||||
wins: standing.wins,
|
||||
podiums: raw.podiums ?? 0,
|
||||
racesCompleted: standing.racesCompleted,
|
||||
};
|
||||
});
|
||||
|
||||
this.viewModel = {
|
||||
leagueId: dto.standings[0]?.leagueId ?? '',
|
||||
standings: standingItems,
|
||||
};
|
||||
async present(leagueId: string): Promise<void> {
|
||||
this.viewModel = await this.getLeagueStandingsUseCase.execute(leagueId);
|
||||
}
|
||||
|
||||
getViewModel(): LeagueStandingsViewModel | null {
|
||||
|
||||
Reference in New Issue
Block a user