42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import type { IStandingRepository } from '../../domain/repositories/IStandingRepository';
|
|
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
|
import type {
|
|
ILeagueStandingsPresenter,
|
|
LeagueStandingsResultDTO,
|
|
LeagueStandingsViewModel,
|
|
} from '../presenters/ILeagueStandingsPresenter';
|
|
import type { UseCase } from '@core/shared/application/UseCase';
|
|
|
|
export interface GetLeagueStandingsUseCaseParams {
|
|
leagueId: string;
|
|
}
|
|
|
|
/**
|
|
* Use Case for retrieving league standings.
|
|
* Orchestrates domain logic and delegates presentation to the presenter.
|
|
*/
|
|
export class GetLeagueStandingsUseCase
|
|
implements
|
|
UseCase<GetLeagueStandingsUseCaseParams, LeagueStandingsResultDTO, LeagueStandingsViewModel, ILeagueStandingsPresenter>
|
|
{
|
|
constructor(
|
|
private readonly standingRepository: IStandingRepository,
|
|
private readonly driverRepository: IDriverRepository,
|
|
) {}
|
|
|
|
async execute(
|
|
params: GetLeagueStandingsUseCaseParams,
|
|
presenter: ILeagueStandingsPresenter,
|
|
): Promise<void> {
|
|
const standings = await this.standingRepository.findByLeagueId(params.leagueId);
|
|
const driverIds = [...new Set(standings.map(s => s.driverId))];
|
|
const drivers = await this.driverRepository.findByIds(driverIds);
|
|
const driverMap = new Map(drivers.map(d => [d.id, { id: d.id, name: d.name }]));
|
|
const dto: LeagueStandingsResultDTO = {
|
|
standings,
|
|
drivers: Array.from(driverMap.values()),
|
|
};
|
|
presenter.reset();
|
|
presenter.present(dto);
|
|
}
|
|
} |