website refactor
This commit is contained in:
43
apps/website/lib/page-queries/media/GetAvatarPageQuery.ts
Normal file
43
apps/website/lib/page-queries/media/GetAvatarPageQuery.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* GetAvatarPageQuery
|
||||
*
|
||||
* Server-side composition for avatar media route.
|
||||
* Fetches avatar binary data and transforms to ViewData.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { AvatarViewDataBuilder } from '@/lib/builders/view-data/AvatarViewDataBuilder';
|
||||
import { AvatarViewData } from '@/lib/view-data/AvatarViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetAvatarPageQuery implements PageQuery<AvatarViewData, { driverId: string }> {
|
||||
async execute(params: { driverId: string }): Promise<Result<AvatarViewData, PresentationError>> {
|
||||
try {
|
||||
// Manual construction: Service creates its own dependencies
|
||||
const service = new MediaService();
|
||||
|
||||
// Fetch avatar data
|
||||
const apiDtoResult = await service.getAvatar(params.driverId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
// Transform to ViewData using builder
|
||||
const output = AvatarViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetAvatarPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
// Static method to avoid object construction in server code
|
||||
static async execute(params: { driverId: string }): Promise<Result<AvatarViewData, PresentationError>> {
|
||||
const query = new GetAvatarPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetCategoryIconPageQuery
|
||||
*
|
||||
* Server-side composition for category icon media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { CategoryIconViewDataBuilder } from '@/lib/builders/view-data/CategoryIconViewDataBuilder';
|
||||
import { CategoryIconViewData } from '@/lib/view-data/CategoryIconViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetCategoryIconPageQuery implements PageQuery<CategoryIconViewData, { categoryId: string }> {
|
||||
async execute(params: { categoryId: string }): Promise<Result<CategoryIconViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getCategoryIcon(params.categoryId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = CategoryIconViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetCategoryIconPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { categoryId: string }): Promise<Result<CategoryIconViewData, PresentationError>> {
|
||||
const query = new GetCategoryIconPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetLeagueCoverPageQuery
|
||||
*
|
||||
* Server-side composition for league cover media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { LeagueCoverViewDataBuilder } from '@/lib/builders/view-data/LeagueCoverViewDataBuilder';
|
||||
import { LeagueCoverViewData } from '@/lib/view-data/LeagueCoverViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetLeagueCoverPageQuery implements PageQuery<LeagueCoverViewData, { leagueId: string }> {
|
||||
async execute(params: { leagueId: string }): Promise<Result<LeagueCoverViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getLeagueCover(params.leagueId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = LeagueCoverViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetLeagueCoverPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { leagueId: string }): Promise<Result<LeagueCoverViewData, PresentationError>> {
|
||||
const query = new GetLeagueCoverPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetLeagueLogoPageQuery
|
||||
*
|
||||
* Server-side composition for league logo media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { LeagueLogoViewDataBuilder } from '@/lib/builders/view-data/LeagueLogoViewDataBuilder';
|
||||
import { LeagueLogoViewData } from '@/lib/view-data/LeagueLogoViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetLeagueLogoPageQuery implements PageQuery<LeagueLogoViewData, { leagueId: string }> {
|
||||
async execute(params: { leagueId: string }): Promise<Result<LeagueLogoViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getLeagueLogo(params.leagueId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = LeagueLogoViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetLeagueLogoPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { leagueId: string }): Promise<Result<LeagueLogoViewData, PresentationError>> {
|
||||
const query = new GetLeagueLogoPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetSponsorLogoPageQuery
|
||||
*
|
||||
* Server-side composition for sponsor logo media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { SponsorLogoViewDataBuilder } from '@/lib/builders/view-data/SponsorLogoViewDataBuilder';
|
||||
import { SponsorLogoViewData } from '@/lib/view-data/SponsorLogoViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetSponsorLogoPageQuery implements PageQuery<SponsorLogoViewData, { sponsorId: string }> {
|
||||
async execute(params: { sponsorId: string }): Promise<Result<SponsorLogoViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getSponsorLogo(params.sponsorId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = SponsorLogoViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetSponsorLogoPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { sponsorId: string }): Promise<Result<SponsorLogoViewData, PresentationError>> {
|
||||
const query = new GetSponsorLogoPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
36
apps/website/lib/page-queries/media/GetTeamLogoPageQuery.ts
Normal file
36
apps/website/lib/page-queries/media/GetTeamLogoPageQuery.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetTeamLogoPageQuery
|
||||
*
|
||||
* Server-side composition for team logo media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { TeamLogoViewDataBuilder } from '@/lib/builders/view-data/TeamLogoViewDataBuilder';
|
||||
import { TeamLogoViewData } from '@/lib/view-data/TeamLogoViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetTeamLogoPageQuery implements PageQuery<TeamLogoViewData, { teamId: string }> {
|
||||
async execute(params: { teamId: string }): Promise<Result<TeamLogoViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getTeamLogo(params.teamId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = TeamLogoViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetTeamLogoPageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { teamId: string }): Promise<Result<TeamLogoViewData, PresentationError>> {
|
||||
const query = new GetTeamLogoPageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* GetTrackImagePageQuery
|
||||
*
|
||||
* Server-side composition for track image media route.
|
||||
*/
|
||||
|
||||
import { PageQuery } from '@/lib/contracts/page-queries/PageQuery';
|
||||
import { Result } from '@/lib/contracts/Result';
|
||||
import { MediaService } from '@/lib/services/media/MediaService';
|
||||
import { TrackImageViewDataBuilder } from '@/lib/builders/view-data/TrackImageViewDataBuilder';
|
||||
import { TrackImageViewData } from '@/lib/view-data/TrackImageViewData';
|
||||
import { PresentationError, mapToPresentationError } from '@/lib/contracts/page-queries/PresentationError';
|
||||
|
||||
export class GetTrackImagePageQuery implements PageQuery<TrackImageViewData, { trackId: string }> {
|
||||
async execute(params: { trackId: string }): Promise<Result<TrackImageViewData, PresentationError>> {
|
||||
try {
|
||||
const service = new MediaService();
|
||||
const apiDtoResult = await service.getTrackImage(params.trackId);
|
||||
|
||||
if (apiDtoResult.isErr()) {
|
||||
return Result.err(mapToPresentationError(apiDtoResult.getError()));
|
||||
}
|
||||
|
||||
const output = TrackImageViewDataBuilder.build(apiDtoResult.unwrap());
|
||||
return Result.ok(output);
|
||||
} catch (err) {
|
||||
console.error('GetTrackImagePageQuery failed:', err);
|
||||
return Result.err('serverError');
|
||||
}
|
||||
}
|
||||
|
||||
static async execute(params: { trackId: string }): Promise<Result<TrackImageViewData, PresentationError>> {
|
||||
const query = new GetTrackImagePageQuery();
|
||||
return query.execute(params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user