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

@@ -1,41 +1,32 @@
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application';
import { Result } from '@core/shared/application/Result';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
export type GetTotalLeaguesInput = {};
export type GetTotalLeaguesResult = {
totalLeagues: number;
};
export interface GetTotalLeaguesInput {}
export type GetTotalLeaguesErrorCode = 'REPOSITORY_ERROR';
export interface GetTotalLeaguesResult {
totalLeagues: number;
}
export class GetTotalLeaguesUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly output: UseCaseOutputPort<GetTotalLeaguesResult>,
) {}
constructor(private readonly leagueRepository: ILeagueRepository) {}
async execute(
_input: GetTotalLeaguesInput,
): Promise<Result<void, ApplicationErrorCode<GetTotalLeaguesErrorCode, { message: string }>>> {
void _input;
): Promise<Result<GetTotalLeaguesResult, ApplicationErrorCode<GetTotalLeaguesErrorCode, { message: string }>>> {
try {
const leagues = await this.leagueRepository.findAll();
const result: GetTotalLeaguesResult = { totalLeagues: leagues.length };
const totalLeagues = leagues.length;
this.output.present(result);
return Result.ok(undefined);
} catch (err) {
const error = err as { message?: string } | undefined;
return Result.ok({ totalLeagues });
} catch (error: unknown) {
const message = error instanceof Error ? error.message : 'Failed to get total leagues';
return Result.err({
code: 'REPOSITORY_ERROR',
details: {
message: error?.message ?? 'Failed to compute total leagues',
},
details: { message },
});
}
}