This commit is contained in:
2025-12-16 21:05:01 +01:00
parent f61e3a4e5a
commit 7532c7ed6d
207 changed files with 7861 additions and 2606 deletions

View File

@@ -1,34 +1,30 @@
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { IProtestRepository } from '../../domain/repositories/IProtestRepository';
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import type { IGetLeagueProtestsPresenter, GetLeagueProtestsResultDTO, GetLeagueProtestsViewModel } from '../presenters/IGetLeagueProtestsPresenter';
import type { UseCase } from '@core/shared/application/UseCase';
import type { AsyncUseCase } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { GetLeagueProtestsResultDTO, ProtestDTO } from '../dto/GetLeagueProtestsResultDTO';
export interface GetLeagueProtestsUseCaseParams {
leagueId: string;
}
export interface GetLeagueProtestsResultDTO {
protests: unknown[];
races: unknown[];
drivers: { id: string; name: string }[];
}
export class GetLeagueProtestsUseCase implements UseCase<GetLeagueProtestsUseCaseParams, GetLeagueProtestsResultDTO, GetLeagueProtestsViewModel, IGetLeagueProtestsPresenter> {
export class GetLeagueProtestsUseCase implements AsyncUseCase<GetLeagueProtestsUseCaseParams, GetLeagueProtestsResultDTO, 'NO_ERROR'> {
constructor(
private readonly raceRepository: IRaceRepository,
private readonly protestRepository: IProtestRepository,
private readonly driverRepository: IDriverRepository,
) {}
async execute(params: GetLeagueProtestsUseCaseParams, presenter: IGetLeagueProtestsPresenter): Promise<void> {
async execute(params: GetLeagueProtestsUseCaseParams): Promise<Result<GetLeagueProtestsResultDTO, ApplicationErrorCode<'NO_ERROR'>>> {
const races = await this.raceRepository.findByLeagueId(params.leagueId);
const protests = [];
const protests: ProtestDTO[] = [];
const raceMap = new Map();
const driverIds = new Set<string>();
for (const race of races) {
raceMap.set(race.id, { id: race.id, name: race.name, date: race.scheduledAt.toISOString() });
raceMap.set(race.id, { id: race.id, name: race.track, date: race.scheduledAt.toISOString() });
const raceProtests = await this.protestRepository.findByRaceId(race.id);
for (const protest of raceProtests) {
protests.push({
@@ -45,14 +41,17 @@ export class GetLeagueProtestsUseCase implements UseCase<GetLeagueProtestsUseCas
}
}
const drivers = await this.driverRepository.findByIds(Array.from(driverIds));
const driverMap = new Map(drivers.map(d => [d.id, { id: d.id, name: d.name }]));
const dto: GetLeagueProtestsResultDTO = {
const drivers: { id: string; name: string }[] = [];
for (const driverId of driverIds) {
const driver = await this.driverRepository.findById(driverId);
if (driver) {
drivers.push({ id: driver.id, name: driver.name });
}
}
return Result.ok({
protests,
races: Array.from(raceMap.values()),
drivers: Array.from(driverMap.values()),
};
presenter.reset();
presenter.present(dto);
drivers,
});
}
}