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,4 +1,4 @@
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
import type { Logger } from '@core/shared/application';
import type { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
import { LeagueMembership } from '../../domain/entities/LeagueMembership';
import { Result } from '@core/shared/application/Result';
@@ -19,10 +19,9 @@ export class JoinLeagueUseCase {
constructor(
private readonly membershipRepository: ILeagueMembershipRepository,
private readonly logger: Logger,
private readonly output: UseCaseOutputPort<JoinLeagueResult>,
) {}
async execute(command: JoinLeagueInput): Promise<Result<void, ApplicationErrorCode<JoinLeagueErrorCode, { message: string }>>> {
async execute(command: JoinLeagueInput): Promise<Result<JoinLeagueResult, ApplicationErrorCode<JoinLeagueErrorCode, { message: string }>>> {
this.logger.debug('Attempting to join league', { command });
const { leagueId, driverId } = command;
@@ -46,11 +45,9 @@ export class JoinLeagueUseCase {
const savedMembership = await this.membershipRepository.saveMembership(membership);
this.logger.info('Successfully joined league', { membershipId: savedMembership.id });
this.output.present({
return Result.ok({
membership: savedMembership,
});
return Result.ok(undefined);
} catch (error) {
const err = error instanceof Error ? error : new Error('Unknown error');
this.logger.error('Failed to join league due to an unexpected error', err);
@@ -60,4 +57,4 @@ export class JoinLeagueUseCase {
});
}
}
}
}