refactor racing use cases

This commit is contained in:
2025-12-21 00:43:42 +01:00
parent e9d6f90bb2
commit c12656d671
308 changed files with 14401 additions and 7419 deletions

View File

@@ -7,34 +7,57 @@
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import type { UseCaseOutputPort } from '@core/shared/application';
import type { Sponsor } from '../../domain/entities/sponsor/Sponsor';
export interface GetSponsorQueryParams {
export type GetSponsorInput = {
sponsorId: string;
}
};
export type GetSponsorResult = {
sponsor: Sponsor;
};
export type GetSponsorErrorCode = 'SPONSOR_NOT_FOUND' | 'REPOSITORY_ERROR';
export class GetSponsorUseCase {
constructor(
private readonly sponsorRepository: ISponsorRepository,
private readonly output: UseCaseOutputPort<GetSponsorResult>,
) {}
async execute(params: GetSponsorQueryParams): Promise<Result<{ sponsor: { id: string; name: string; logoUrl?: string; websiteUrl?: string } } | null, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
async execute(input: GetSponsorInput): Promise<Result<void, ApplicationErrorCode<GetSponsorErrorCode, { message: string }>>> {
try {
const sponsor = await this.sponsorRepository.findById(params.sponsorId);
const sponsor = await this.sponsorRepository.findById(input.sponsorId);
if (!sponsor) {
return Result.ok(null);
return Result.err({
code: 'SPONSOR_NOT_FOUND',
details: {
message: 'Sponsor not found',
},
});
}
const sponsorData = {
id: sponsor.id,
name: sponsor.name,
logoUrl: sponsor.logoUrl,
websiteUrl: sponsor.websiteUrl,
const result: GetSponsorResult = {
sponsor,
};
return Result.ok({ sponsor: sponsorData });
} catch {
return Result.err({ code: 'REPOSITORY_ERROR', message: 'Failed to fetch sponsor' });
this.output.present(result);
return Result.ok(undefined);
} catch (error: unknown) {
const message =
error instanceof Error && typeof error.message === 'string'
? error.message
: 'Failed to load sponsor';
return Result.err({
code: 'REPOSITORY_ERROR',
details: {
message,
},
});
}
}
}