refactor use cases
This commit is contained in:
@@ -1,34 +1,18 @@
|
||||
/**
|
||||
* 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 type { ISponsorRepository } from '../../domain/repositories/ISponsorRepository';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
type GetSponsorsResult = {
|
||||
export interface GetSponsorsInput {}
|
||||
|
||||
export interface GetSponsorsResult {
|
||||
sponsors: Sponsor[];
|
||||
};
|
||||
}
|
||||
|
||||
export class GetSponsorsUseCase {
|
||||
constructor(
|
||||
private readonly sponsorRepository: ISponsorRepository,
|
||||
private readonly output: UseCaseOutputPort<GetSponsorsResult>,
|
||||
) {}
|
||||
constructor(private readonly sponsorRepository: ISponsorRepository) {}
|
||||
|
||||
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' });
|
||||
}
|
||||
async execute(_input: GetSponsorsInput): Promise<Result<GetSponsorsResult, never>> {
|
||||
const sponsors = await this.sponsorRepository.findAll();
|
||||
return Result.ok({ sponsors });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user