Files
gridpilot.gg/apps/website/lib/services/media/MediaService.ts
2025-12-17 22:17:02 +01:00

53 lines
1.5 KiB
TypeScript

import type { MediaApiClient } from '../../api/media/MediaApiClient';
import type { MediaPresenter } from '../../presenters/MediaPresenter';
import type { UploadMediaInputDto, GetMediaOutputDto, DeleteMediaOutputDto } from '../../dtos';
import type { MediaViewModel, UploadMediaViewModel, DeleteMediaViewModel } from '../../view-models';
/**
* Media Service
*
* Orchestrates media operations by coordinating API calls and presentation logic.
* All dependencies are injected via constructor.
*/
export class MediaService {
constructor(
private readonly apiClient: MediaApiClient,
private readonly presenter: MediaPresenter
) {}
/**
* Upload media file with presentation transformation
*/
async uploadMedia(input: UploadMediaInputDto): Promise<UploadMediaViewModel> {
try {
const dto = await this.apiClient.uploadMedia(input);
return this.presenter.presentUpload(dto);
} catch (error) {
throw error;
}
}
/**
* Get media by ID with presentation transformation
*/
async getMedia(mediaId: string): Promise<MediaViewModel> {
try {
const dto = await this.apiClient.getMedia(mediaId);
return this.presenter.presentMedia(dto);
} catch (error) {
throw error;
}
}
/**
* Delete media by ID with presentation transformation
*/
async deleteMedia(mediaId: string): Promise<DeleteMediaViewModel> {
try {
const dto = await this.apiClient.deleteMedia(mediaId);
return this.presenter.presentDelete(dto);
} catch (error) {
throw error;
}
}
}