refactor core presenters

This commit is contained in:
2025-12-19 19:42:19 +01:00
parent 8116fe888f
commit 94fc538f44
228 changed files with 2817 additions and 3097 deletions

View File

@@ -1,23 +1,23 @@
import type { IRaceRepository } from '../../domain/repositories/IRaceRepository';
import type { GetTotalRacesResultDTO } from '../presenters/IGetTotalRacesPresenter';
import type { GetTotalRacesOutputPort } from '../ports/output/GetTotalRacesOutputPort';
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 class GetTotalRacesUseCase implements AsyncUseCase<void, GetTotalRacesResultDTO, 'REPOSITORY_ERROR'>
export class GetTotalRacesUseCase implements AsyncUseCase<void, GetTotalRacesOutputPort, 'REPOSITORY_ERROR'>
{
constructor(
private readonly raceRepository: IRaceRepository,
private readonly logger: Logger,
) {}
async execute(): Promise<Result<GetTotalRacesResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
async execute(): Promise<Result<GetTotalRacesOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const races = await this.raceRepository.findAll();
const dto: GetTotalRacesResultDTO = { totalRaces: races.length };
const output: GetTotalRacesOutputPort = { totalRaces: races.length };
return Result.ok(dto);
return Result.ok(output);
} 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' } });