50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { DeleteMediaViewModel } from '@/lib/view-models/DeleteMediaViewModel';
|
|
import { MediaViewModel } from '@/lib/view-models/MediaViewModel';
|
|
import { UploadMediaViewModel } from '@/lib/view-models/UploadMediaViewModel';
|
|
import type { MediaApiClient } from '../../api/media/MediaApiClient';
|
|
|
|
// TODO: Move these types to apps/website/lib/types/generated when available
|
|
type UploadMediaInputDto = { file: File; type: string; category?: string };
|
|
|
|
/**
|
|
* Media Service
|
|
*
|
|
* Orchestrates media operations by coordinating API calls and view model creation.
|
|
* All dependencies are injected via constructor.
|
|
*/
|
|
export class MediaService {
|
|
constructor(
|
|
private readonly apiClient: MediaApiClient
|
|
) {}
|
|
|
|
/**
|
|
* Upload media file with view model transformation
|
|
*/
|
|
async uploadMedia(input: UploadMediaInputDto): Promise<UploadMediaViewModel> {
|
|
const dto = await this.apiClient.uploadMedia(input);
|
|
return new UploadMediaViewModel(dto);
|
|
}
|
|
|
|
/**
|
|
* Get media by ID with view model transformation
|
|
*/
|
|
async getMedia(mediaId: string): Promise<MediaViewModel> {
|
|
const dto = await this.apiClient.getMedia(mediaId);
|
|
return new MediaViewModel(dto);
|
|
}
|
|
|
|
/**
|
|
* Delete media by ID with view model transformation
|
|
*/
|
|
async deleteMedia(mediaId: string): Promise<DeleteMediaViewModel> {
|
|
const dto = await this.apiClient.deleteMedia(mediaId);
|
|
return new DeleteMediaViewModel(dto);
|
|
}
|
|
|
|
/**
|
|
* Get team logo URL
|
|
*/
|
|
getTeamLogo(teamId: string): string {
|
|
return `/api/media/teams/${teamId}/logo`;
|
|
}
|
|
} |