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,23 +1,31 @@
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
import type { ITotalDriversPresenter, TotalDriversResultDTO } from '../presenters/ITotalDriversPresenter';
import type { UseCase } from '@core/shared/application/UseCase';
import type { TotalDriversResultDTO } from '../presenters/ITotalDriversPresenter';
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';
/**
* Use Case for retrieving total number of drivers.
*/
export class GetTotalDriversUseCase
implements UseCase<void, TotalDriversResultDTO, any, ITotalDriversPresenter>
export class GetTotalDriversUseCase implements AsyncUseCase<void, TotalDriversResultDTO, 'REPOSITORY_ERROR'>
{
constructor(private readonly driverRepository: IDriverRepository) {}
constructor(
private readonly driverRepository: IDriverRepository,
private readonly logger: Logger,
) {}
async execute(_input: void, presenter: ITotalDriversPresenter): Promise<void> {
presenter.reset();
async execute(): Promise<Result<TotalDriversResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const drivers = await this.driverRepository.findAll();
const dto: TotalDriversResultDTO = {
totalDrivers: drivers.length,
};
const drivers = await this.driverRepository.findAll();
const dto: TotalDriversResultDTO = {
totalDrivers: drivers.length,
};
presenter.present(dto);
return Result.ok(dto);
} 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' } });
}
}
}