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,5 +1,5 @@
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import type { TotalDriversResultDTO } from '../presenters/ITotalDriversPresenter';
import type { TotalDriversOutputPort } from '../ports/output/TotalDriversOutputPort';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { AsyncUseCase } from '@core/shared/application';
@@ -8,21 +8,21 @@ import type { Logger } from '@core/shared/application';
/**
* Use Case for retrieving total number of drivers.
*/
export class GetTotalDriversUseCase implements AsyncUseCase<void, TotalDriversResultDTO, 'REPOSITORY_ERROR'>
export class GetTotalDriversUseCase implements AsyncUseCase<void, TotalDriversOutputPort, 'REPOSITORY_ERROR'>
{
constructor(
private readonly driverRepository: IDriverRepository,
private readonly logger: Logger,
) {}
async execute(): Promise<Result<TotalDriversResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
async execute(): Promise<Result<TotalDriversOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const drivers = await this.driverRepository.findAll();
const dto: TotalDriversResultDTO = {
const output: TotalDriversOutputPort = {
totalDrivers: drivers.length,
};
return Result.ok(dto);
return Result.ok(output);
} catch (error) {
this.logger.error('Error retrieving total drivers', error as Error);
return Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'Failed to retrieve total drivers' } });