refactor core presenters
This commit is contained in:
@@ -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' } });
|
||||
|
||||
Reference in New Issue
Block a user