28 lines
736 B
TypeScript
28 lines
736 B
TypeScript
import { LeagueRepository, LeagueData } from '../ports/LeagueRepository';
|
|
|
|
export interface SearchLeaguesQuery {
|
|
query: string;
|
|
limit?: number;
|
|
offset?: number;
|
|
}
|
|
|
|
export class SearchLeaguesUseCase {
|
|
constructor(private readonly leagueRepository: LeagueRepository) {}
|
|
|
|
async execute(query: SearchLeaguesQuery): Promise<LeagueData[]> {
|
|
// Validate query
|
|
if (!query.query || query.query.trim() === '') {
|
|
throw new Error('Search query is required');
|
|
}
|
|
|
|
// Search leagues
|
|
const results = await this.leagueRepository.search(query.query);
|
|
|
|
// Apply limit and offset
|
|
const limit = query.limit || 10;
|
|
const offset = query.offset || 0;
|
|
|
|
return results.slice(offset, offset + limit);
|
|
}
|
|
}
|