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,20 +1,26 @@
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { IGetTotalRacesPresenter, GetTotalRacesResultDTO, GetTotalRacesViewModel } from '../presenters/IGetTotalRacesPresenter';
import type { UseCase } from '@core/shared/application/UseCase';
import type { GetTotalRacesResultDTO } from '../presenters/IGetTotalRacesPresenter';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { AsyncUseCase } from '@core/shared/application';
import type { Logger } from '@core/shared/application';
export interface GetTotalRacesUseCaseParams {}
export class GetTotalRacesUseCase implements AsyncUseCase<void, GetTotalRacesResultDTO, 'REPOSITORY_ERROR'>
{
constructor(
private readonly raceRepository: IRaceRepository,
private readonly logger: Logger,
) {}
export interface GetTotalRacesResultDTO {
totalRaces: number;
}
async execute(): Promise<Result<GetTotalRacesResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const races = await this.raceRepository.findAll();
const dto: GetTotalRacesResultDTO = { totalRaces: races.length };
export class GetTotalRacesUseCase implements UseCase<GetTotalRacesUseCaseParams, GetTotalRacesResultDTO, GetTotalRacesViewModel, IGetTotalRacesPresenter> {
constructor(private readonly raceRepository: IRaceRepository) {}
async execute(params: GetTotalRacesUseCaseParams, presenter: IGetTotalRacesPresenter): Promise<void> {
const races = await this.raceRepository.findAll();
const dto: GetTotalRacesResultDTO = { totalRaces: races.length };
presenter.reset();
presenter.present(dto);
return Result.ok(dto);
} catch (error) {
this.logger.error('Error retrieving total races', error as Error);
return Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'Failed to retrieve total races' } });
}
}
}