Files
gridpilot.gg/core/racing/application/use-cases/GetSponsorsUseCase.ts
2025-12-21 00:43:42 +01:00

34 lines
1.0 KiB
TypeScript

/**
* Application Use Case: GetSponsorsUseCase
*
* Retrieves all sponsors.
*/
import type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
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<void, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
try {
const sponsors = await this.sponsorRepository.findAll();
this.output.present({ sponsors });
return Result.ok(undefined);
} catch {
return Result.err({ code: 'REPOSITORY_ERROR', message: 'Failed to fetch sponsors' });
}
}
}