This commit is contained in:
2025-12-16 18:17:48 +01:00
parent 362894d1a5
commit ec7c0b8f2a
94 changed files with 4240 additions and 983 deletions

View File

@@ -7,29 +7,29 @@ import type {
LeagueFullConfigData,
LeagueConfigFormViewModel,
} from '../presenters/ILeagueFullConfigPresenter';
import type { UseCase } from '@core/shared/application/UseCase';
import { EntityNotFoundError } from '../errors/RacingApplicationError';
import type { AsyncUseCase } from '@core/shared/application';
import { Result } from '@core/shared/result/Result';
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
/**
* Use Case for retrieving a league's full configuration.
* Orchestrates domain logic and delegates presentation to the presenter.
*/
export class GetLeagueFullConfigUseCase
implements UseCase<{ leagueId: string }, LeagueFullConfigData, LeagueConfigFormViewModel, ILeagueFullConfigPresenter>
{
export class GetLeagueFullConfigUseCase implements AsyncUseCase<{ leagueId: string }, Result<LeagueConfigFormViewModel, RacingDomainValidationError>> {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly seasonRepository: ISeasonRepository,
private readonly leagueScoringConfigRepository: ILeagueScoringConfigRepository,
private readonly gameRepository: IGameRepository,
private readonly presenter: ILeagueFullConfigPresenter,
) {}
async execute(params: { leagueId: string }, presenter: ILeagueFullConfigPresenter): Promise<void> {
async execute(params: { leagueId: string }): Promise<Result<LeagueConfigFormViewModel, RacingDomainValidationError>> {
const { leagueId } = params;
const league = await this.leagueRepository.findById(leagueId);
if (!league) {
throw new EntityNotFoundError({ entity: 'league', id: leagueId });
return Result.err(new RacingDomainValidationError(`League with id ${leagueId} not found`));
}
const seasons = await this.seasonRepository.findByLeagueId(leagueId);
@@ -54,7 +54,13 @@ export class GetLeagueFullConfigUseCase
...(game ? { game } : {}),
};
presenter.reset();
presenter.present(data);
this.presenter.reset();
this.presenter.present(data);
const viewModel = this.presenter.getViewModel();
if (!viewModel) {
return Result.err(new RacingDomainValidationError('Failed to present league config'));
}
return Result.ok(viewModel);
}
}