refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -3,7 +3,6 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { Logger } from '@core/shared/application';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import type { Race } from '../../domain/entities/Race';
import type { League } from '../../domain/entities/League';
@@ -18,21 +17,15 @@ export interface GetAllRacesResult {
export type GetAllRacesErrorCode = 'REPOSITORY_ERROR';
export class GetAllRacesUseCase {
private output: UseCaseOutputPort<GetAllRacesResult> | null = null;
constructor(
private readonly raceRepository: IRaceRepository,
private readonly leagueRepository: ILeagueRepository,
private readonly logger: Logger,
) {}
setOutput(output: UseCaseOutputPort<GetAllRacesResult>) {
this.output = output;
}
async execute(
_input: GetAllRacesInput,
): Promise<Result<void, ApplicationErrorCode<GetAllRacesErrorCode, { message: string }>>> {
): Promise<Result<GetAllRacesResult, ApplicationErrorCode<GetAllRacesErrorCode, { message: string }>>> {
void _input;
this.logger.debug('Executing GetAllRacesUseCase');
try {
@@ -46,11 +39,7 @@ export class GetAllRacesUseCase {
};
this.logger.debug('Successfully retrieved all races.');
if (!this.output) {
throw new Error('Output not set');
}
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error) {
this.logger.error(
'Error executing GetAllRacesUseCase',
@@ -62,4 +51,4 @@ export class GetAllRacesUseCase {
});
}
}
}
}