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

@@ -10,7 +10,7 @@ import type { IRaceRepository } from '../../domain/repositories/IRaceRepository'
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import { isLeagueStewardOrHigherRole } from '../../domain/types/LeagueRoles';
import { Result } from '@core/shared/application/Result';
import { Logger, UseCaseOutputPort } from '@core/shared/application';
import { Logger } from '@core/shared/application';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
export type RequestProtestDefenseInput = {
@@ -38,12 +38,11 @@ export class RequestProtestDefenseUseCase {
private readonly raceRepository: IRaceRepository,
private readonly membershipRepository: ILeagueMembershipRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<RequestProtestDefenseResult>,
) {}
async execute(
input: RequestProtestDefenseInput,
): Promise<Result<void, ApplicationErrorCode<RequestProtestDefenseErrorCode, { message: string }>>> {
): Promise<Result<RequestProtestDefenseResult, ApplicationErrorCode<RequestProtestDefenseErrorCode, { message: string }>>> {
try {
const protest = await this.protestRepository.findById(input.protestId);
if (!protest) {
@@ -86,13 +85,11 @@ export class RequestProtestDefenseUseCase {
status: 'defense_requested',
};
this.output.present(result);
return Result.ok(undefined);
return Result.ok(result);
} catch (error: unknown) {
const message = error instanceof Error ? error.message : 'Failed to request protest defense';
this.logger.error('RequestProtestDefenseUseCase.execute failed', error instanceof Error ? error : undefined);
return Result.err({ code: 'REPOSITORY_ERROR', details: { message } });
}
}
}
}