presenter refactoring
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import type { IGetMediaPresenter, GetMediaResult } from '@core/media/application/presenters/IGetMediaPresenter';
|
||||
import type { GetMediaOutputDTO } from '../dtos/GetMediaOutputDTO';
|
||||
|
||||
// The HTTP-facing DTO (or null when not found)
|
||||
export type GetMediaViewModel = GetMediaOutputDTO | null;
|
||||
|
||||
export class GetMediaPresenter implements IGetMediaPresenter {
|
||||
private result: GetMediaResult | null = null;
|
||||
@@ -7,8 +11,21 @@ export class GetMediaPresenter implements IGetMediaPresenter {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
get viewModel(): GetMediaResult {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
return this.result;
|
||||
get viewModel(): GetMediaViewModel {
|
||||
if (!this.result || !this.result.success || !this.result.media) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const media = this.result.media;
|
||||
|
||||
return {
|
||||
id: media.id,
|
||||
url: media.url,
|
||||
type: media.type,
|
||||
// Best-effort mapping from arbitrary metadata
|
||||
category: (media.metadata as { category?: string } | undefined)?.category,
|
||||
uploadedAt: media.uploadedAt,
|
||||
size: media.size,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user