30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
import { Result } from '@core/shared/domain/Result';
|
|
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
|
import type { Sponsor } from '../../domain/entities/sponsor/Sponsor';
|
|
import type { SponsorRepository } from '../../domain/repositories/SponsorRepository';
|
|
|
|
export interface GetSponsorsInput {}
|
|
|
|
export interface GetSponsorsResult {
|
|
sponsors: Sponsor[];
|
|
}
|
|
|
|
export type GetSponsorsErrorCode = 'REPOSITORY_ERROR';
|
|
|
|
export class GetSponsorsUseCase {
|
|
constructor(private readonly sponsorRepository: SponsorRepository) {}
|
|
|
|
async execute(_input: GetSponsorsInput): Promise<Result<GetSponsorsResult, ApplicationErrorCode<GetSponsorsErrorCode, { message: string }>>> {
|
|
void _input;
|
|
try {
|
|
const sponsors = await this.sponsorRepository.findAll();
|
|
return Result.ok({ sponsors });
|
|
} catch (error) {
|
|
return Result.err({
|
|
code: 'REPOSITORY_ERROR',
|
|
details: { message: error instanceof Error ? error.message : 'Unknown error' },
|
|
});
|
|
}
|
|
}
|
|
}
|