integration tests
This commit is contained in:
27
core/leagues/application/use-cases/SearchLeaguesUseCase.ts
Normal file
27
core/leagues/application/use-cases/SearchLeaguesUseCase.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user