refactor
This commit is contained in:
@@ -2,23 +2,24 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type {
|
||||
IAllRacesPagePresenter,
|
||||
AllRacesPageResultDTO,
|
||||
AllRacesPageViewModel,
|
||||
AllRacesListItemViewModel,
|
||||
AllRacesFilterOptionsViewModel,
|
||||
} from '../presenters/IAllRacesPagePresenter';
|
||||
import type { UseCase } from '@core/shared/application';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import { Result } from '@core/shared/result/Result';
|
||||
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
|
||||
|
||||
export class GetAllRacesPageDataUseCase
|
||||
implements UseCase<void, AllRacesPageResultDTO, AllRacesPageViewModel, IAllRacesPagePresenter> {
|
||||
implements AsyncUseCase<void, Result<AllRacesPageResultDTO, RacingDomainValidationError>> {
|
||||
constructor(
|
||||
private readonly raceRepository: IRaceRepository,
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(_input: void, presenter: IAllRacesPagePresenter): Promise<void> {
|
||||
async execute(): Promise<Result<AllRacesPageResultDTO, RacingDomainValidationError>> {
|
||||
this.logger.debug('Executing GetAllRacesPageDataUseCase');
|
||||
try {
|
||||
const [allRaces, allLeagues] = await Promise.all([
|
||||
@@ -64,12 +65,11 @@ export class GetAllRacesPageDataUseCase
|
||||
filters,
|
||||
};
|
||||
|
||||
presenter.reset();
|
||||
presenter.present(viewModel);
|
||||
this.logger.debug('Successfully presented all races page data.');
|
||||
this.logger.debug('Successfully retrieved all races page data.');
|
||||
return Result.ok(viewModel);
|
||||
} catch (error) {
|
||||
this.logger.error('Error executing GetAllRacesPageDataUseCase', { error });
|
||||
throw error;
|
||||
this.logger.error('Error executing GetAllRacesPageDataUseCase', error instanceof Error ? error : new Error(String(error)));
|
||||
return Result.err(new RacingDomainValidationError(error instanceof Error ? error.message : 'Unknown error occurred'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user