This commit is contained in:
2025-12-16 21:44:20 +01:00
parent 7532c7ed6d
commit 8c67081953
38 changed files with 818 additions and 1321 deletions

View File

@@ -4,15 +4,15 @@ import type { IDriverStatsService } from '../../domain/services/IDriverStatsServ
import type { IImageServicePort } from '../ports/IImageServicePort';
import type { DriversLeaderboardResultDTO } from '../presenters/IDriversLeaderboardPresenter';
import type { AsyncUseCase, Logger } from '@core/shared/application';
import { Result } from '@/shared/application/Result';
import { RacingDomainValidationError } from '../../domain/errors/RacingDomainError';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
/**
* Use Case for retrieving driver leaderboard data.
* Orchestrates domain logic and returns result.
*/
export class GetDriversLeaderboardUseCase
implements AsyncUseCase<void, Result<DriversLeaderboardResultDTO, RacingDomainValidationError>>
implements AsyncUseCase<void, DriversLeaderboardResultDTO, 'REPOSITORY_ERROR'>
{
constructor(
private readonly driverRepository: IDriverRepository,
@@ -22,7 +22,7 @@ export class GetDriversLeaderboardUseCase
private readonly logger: Logger,
) {}
async execute(): Promise<Result<DriversLeaderboardResultDTO, RacingDomainValidationError>> {
async execute(): Promise<Result<DriversLeaderboardResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR', { message: string }>>> {
this.logger.debug('Executing GetDriversLeaderboardUseCase');
try {
const drivers = await this.driverRepository.findAll();
@@ -50,7 +50,10 @@ export class GetDriversLeaderboardUseCase
return Result.ok(dto);
} catch (error) {
this.logger.error('Error executing GetDriversLeaderboardUseCase', error instanceof Error ? error : new Error(String(error)));
return Result.err(new RacingDomainValidationError(error instanceof Error ? error.message : 'Unknown error occurred'));
return Result.err({
code: 'REPOSITORY_ERROR',
details: { message: error instanceof Error ? error.message : 'Unknown error occurred' },
});
}
}
}