wip
This commit is contained in:
@@ -2,30 +2,36 @@ import type { IDriverRepository } from '../../domain/repositories/IDriverReposit
|
||||
import type { IRankingService } from '../../domain/services/IRankingService';
|
||||
import type { IDriverStatsService } from '../../domain/services/IDriverStatsService';
|
||||
import type { IImageServicePort } from '../ports/IImageServicePort';
|
||||
import type { IDriversLeaderboardPresenter } from '../presenters/IDriversLeaderboardPresenter';
|
||||
import type { AsyncUseCase } from '@gridpilot/shared/application';
|
||||
import type {
|
||||
IDriversLeaderboardPresenter,
|
||||
DriversLeaderboardResultDTO,
|
||||
DriversLeaderboardViewModel,
|
||||
} from '../presenters/IDriversLeaderboardPresenter';
|
||||
import type { UseCase } from '@gridpilot/shared/application/UseCase';
|
||||
|
||||
/**
|
||||
* Use Case for retrieving driver leaderboard data.
|
||||
* Orchestrates domain logic and delegates presentation to the presenter.
|
||||
*/
|
||||
export class GetDriversLeaderboardUseCase
|
||||
implements AsyncUseCase<void, void> {
|
||||
implements UseCase<void, DriversLeaderboardResultDTO, DriversLeaderboardViewModel, IDriversLeaderboardPresenter>
|
||||
{
|
||||
constructor(
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly rankingService: IRankingService,
|
||||
private readonly driverStatsService: IDriverStatsService,
|
||||
private readonly imageService: IImageServicePort,
|
||||
public readonly presenter: IDriversLeaderboardPresenter,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
async execute(_input: void, presenter: IDriversLeaderboardPresenter): Promise<void> {
|
||||
presenter.reset();
|
||||
|
||||
const drivers = await this.driverRepository.findAll();
|
||||
const rankings = this.rankingService.getAllDriverRankings();
|
||||
|
||||
const stats: Record<string, any> = {};
|
||||
const avatarUrls: Record<string, string> = {};
|
||||
|
||||
|
||||
const stats: DriversLeaderboardResultDTO['stats'] = {};
|
||||
const avatarUrls: DriversLeaderboardResultDTO['avatarUrls'] = {};
|
||||
|
||||
for (const driver of drivers) {
|
||||
const driverStats = this.driverStatsService.getDriverStats(driver.id);
|
||||
if (driverStats) {
|
||||
@@ -33,7 +39,14 @@ export class GetDriversLeaderboardUseCase
|
||||
}
|
||||
avatarUrls[driver.id] = this.imageService.getDriverAvatar(driver.id);
|
||||
}
|
||||
|
||||
this.presenter.present(drivers, rankings, stats, avatarUrls);
|
||||
|
||||
const dto: DriversLeaderboardResultDTO = {
|
||||
drivers,
|
||||
rankings,
|
||||
stats,
|
||||
avatarUrls,
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user