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

@@ -5,31 +5,28 @@
*/
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
import type { GetSponsorsOutputPort } from '../ports/output/GetSponsorsOutputPort';
import type { Sponsor } from '../../domain/entities/sponsor/Sponsor';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
type GetSponsorsResult = {
sponsors: Sponsor[];
};
export class GetSponsorsUseCase {
constructor(
private readonly sponsorRepository: ISponsorRepository,
private readonly output: UseCaseOutputPort<GetSponsorsResult>,
) {}
async execute(): Promise<Result<GetSponsorsOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
async execute(): Promise<Result<void, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const sponsors = await this.sponsorRepository.findAll();
const outputPort: GetSponsorsOutputPort = {
sponsors: sponsors.map(sponsor => ({
id: sponsor.id,
name: sponsor.name,
contactEmail: sponsor.contactEmail,
websiteUrl: sponsor.websiteUrl,
logoUrl: sponsor.logoUrl,
createdAt: sponsor.createdAt,
})),
};
this.output.present({ sponsors });
return Result.ok(outputPort);
return Result.ok(undefined);
} catch {
return Result.err({ code: 'REPOSITORY_ERROR', message: 'Failed to fetch sponsors' });
}