view data fixes
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 5m54s
Contract Testing / contract-snapshot (pull_request) Has been skipped

This commit is contained in:
2026-01-23 13:04:05 +01:00
parent d97f50ed72
commit e22033be38
24 changed files with 605 additions and 455 deletions

View File

@@ -1,37 +1,40 @@
import type { GetMediaOutputDTO } from '@/lib/types/generated/GetMediaOutputDTO';
import type { MediaViewData } from '@/lib/view-data/MediaViewData';
import { ViewModel } from "../contracts/view-models/ViewModel";
type MediaAssetViewData = MediaViewData['assets'][number];
/**
* Media View Model
*
* Represents media information for the UI layer
* Client-only ViewModel created from ViewData (never DTO).
* Represents a single media asset card in the UI.
*/
import { ViewModel } from "../contracts/view-models/ViewModel";
export class MediaViewModel extends ViewModel {
id: string;
url: string;
type: 'image' | 'video' | 'document';
category?: 'avatar' | 'team-logo' | 'league-cover' | 'race-result';
uploadedAt: Date;
size?: number;
src: string;
title: string;
category: string;
date?: string;
dimensions?: string;
constructor(dto: GetMediaOutputDTO) {
this.id = dto.id;
this.url = dto.url;
this.type = dto.type as 'image' | 'video' | 'document';
this.uploadedAt = new Date(dto.uploadedAt);
if (dto.category !== undefined) this.category = dto.category as 'avatar' | 'team-logo' | 'league-cover' | 'race-result';
if (dto.size !== undefined) this.size = dto.size;
constructor(viewData: MediaAssetViewData) {
super();
this.id = viewData.id;
this.src = viewData.src;
this.title = viewData.title;
this.category = viewData.category;
if (viewData.date !== undefined) this.date = viewData.date;
if (viewData.dimensions !== undefined) this.dimensions = viewData.dimensions;
}
/** UI-specific: Formatted file size */
get formattedSize(): string {
if (!this.size) return 'Unknown';
const kb = this.size / 1024;
/** UI-specific: Combined subtitle used by MediaCard */
get subtitle(): string {
return `${this.category}${this.dimensions ? `${this.dimensions}` : ''}`;
}
if (kb < 1024) return `${kb.toFixed(2)} KB`;
const mb = kb / 1024;
return `${mb.toFixed(2)} MB`;
/** UI-specific: Whether any metadata is present */
get hasMetadata(): boolean {
return !!this.date || !!this.dimensions;
}
}