Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
32 lines
1.4 KiB
TypeScript
32 lines
1.4 KiB
TypeScript
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
|
import { Result } from '@/lib/contracts/Result';
|
|
import { LeagueService, type LeagueDetailData } from '@/lib/services/leagues/LeagueService';
|
|
import { type PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
|
import { LeagueDetailViewDataBuilder } from '@/lib/builders/view-data/LeagueDetailViewDataBuilder';
|
|
import { LeagueDetailViewData } from '@/lib/view-data/LeagueDetailViewData';
|
|
|
|
/**
|
|
* LeagueDetail page query
|
|
* Returns the raw API DTO for the league detail page
|
|
* No DI container usage - constructs dependencies explicitly
|
|
*/
|
|
export class LeagueDetailPageQuery implements PageQuery<LeagueDetailViewData, string, PresentationError> {
|
|
async execute(leagueId: string): Promise<Result<LeagueDetailViewData, PresentationError>> {
|
|
const service = new LeagueService();
|
|
const result = await service.getLeagueDetailData(leagueId);
|
|
|
|
if (result.isErr()) {
|
|
return Result.err(mapToPresentationError(result.getError()));
|
|
}
|
|
|
|
const viewData = LeagueDetailViewDataBuilder.build(result.unwrap());
|
|
return Result.ok(viewData);
|
|
}
|
|
|
|
// Static method to avoid object construction in server code
|
|
static async execute(leagueId: string): Promise<Result<LeagueDetailViewData, PresentationError>> {
|
|
const query = new LeagueDetailPageQuery();
|
|
return query.execute(leagueId);
|
|
}
|
|
}
|