view models

This commit is contained in:
2025-12-18 01:20:23 +01:00
parent 7c449af311
commit cc2553876a
216 changed files with 485 additions and 10179 deletions

View File

@@ -1,53 +1,41 @@
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';
import { MediaViewModel, UploadMediaViewModel, DeleteMediaViewModel } from '../../view-models';
// TODO: Move these types to apps/website/lib/types/generated when available
type UploadMediaInputDto = { url: string; mediaType: string; entityType: string; entityId: string };
/**
* Media Service
*
* Orchestrates media operations by coordinating API calls and presentation logic.
* 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,
private readonly presenter: MediaPresenter
private readonly apiClient: MediaApiClient
) {}
/**
* Upload media file with presentation transformation
* Upload media file with view model transformation
*/
async uploadMedia(input: UploadMediaInputDto): Promise<UploadMediaViewModel> {
try {
const dto = await this.apiClient.uploadMedia(input);
return this.presenter.presentUpload(dto);
} catch (error) {
throw error;
}
const dto = await this.apiClient.uploadMedia(input);
return new UploadMediaViewModel(dto);
}
/**
* Get media by ID with presentation transformation
* Get media by ID with view model transformation
*/
async getMedia(mediaId: string): Promise<MediaViewModel> {
try {
const dto = await this.apiClient.getMedia(mediaId);
return this.presenter.presentMedia(dto);
} catch (error) {
throw error;
}
const dto = await this.apiClient.getMedia(mediaId);
return new MediaViewModel(dto);
}
/**
* Delete media by ID with presentation transformation
* Delete media by ID with view model transformation
*/
async deleteMedia(mediaId: string): Promise<DeleteMediaViewModel> {
try {
const dto = await this.apiClient.deleteMedia(mediaId);
return this.presenter.presentDelete(dto);
} catch (error) {
throw error;
}
const dto = await this.apiClient.deleteMedia(mediaId);
return new DeleteMediaViewModel(dto);
}
}