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,7 +1,6 @@
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/UseCaseOutputPort';
import type { League } from '../../domain/entities/League';
export type GetLeagueAdminInput = {
@@ -17,21 +16,18 @@ export type GetLeagueAdminErrorCode = 'LEAGUE_NOT_FOUND' | 'REPOSITORY_ERROR';
export class GetLeagueAdminUseCase {
constructor(
private readonly leagueRepository: ILeagueRepository,
private readonly output: UseCaseOutputPort<GetLeagueAdminResult>,
) {}
async execute(
input: GetLeagueAdminInput,
): Promise<Result<void, ApplicationErrorCode<GetLeagueAdminErrorCode, { message: string }>>> {
): Promise<Result<GetLeagueAdminResult, ApplicationErrorCode<GetLeagueAdminErrorCode, { message: string }>>> {
try {
const league = await this.leagueRepository.findById(input.leagueId);
if (!league) {
return Result.err({ code: 'LEAGUE_NOT_FOUND', details: { message: 'League not found' } });
}
this.output.present({ league });
return Result.ok(undefined);
return Result.ok({ league });
} catch (error) {
const err = error instanceof Error ? error : new Error('Unknown error');
return Result.err({
@@ -40,4 +36,4 @@ export class GetLeagueAdminUseCase {
});
}
}
}
}