view data fixes
This commit is contained in:
@@ -1,27 +1,29 @@
|
||||
// Note: No generated DTO available for Avatar yet
|
||||
interface AvatarDTO {
|
||||
driverId: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import { AvatarDisplay } from "../display-objects/AvatarDisplay";
|
||||
import { AvatarViewData } from "@/lib/view-data/AvatarViewData";
|
||||
|
||||
/**
|
||||
* Avatar View Model
|
||||
*
|
||||
* Represents avatar information for the UI layer
|
||||
* Represents avatar information for the UI layer.
|
||||
* Transforms AvatarViewData into UI-ready state with formatting and derived fields.
|
||||
*/
|
||||
export class AvatarViewModel {
|
||||
driverId: string;
|
||||
avatarUrl?: string;
|
||||
export class AvatarViewModel extends ViewModel {
|
||||
// UI-specific derived fields (primitive outputs only)
|
||||
readonly bufferBase64: string;
|
||||
readonly contentTypeLabel: string;
|
||||
readonly hasValidData: boolean;
|
||||
|
||||
constructor(dto: AvatarDTO) {
|
||||
this.driverId = dto.driverId;
|
||||
if (dto.avatarUrl !== undefined) {
|
||||
this.avatarUrl = dto.avatarUrl;
|
||||
}
|
||||
}
|
||||
constructor(viewData: AvatarViewData) {
|
||||
super();
|
||||
|
||||
/** UI-specific: Whether the driver has an avatar */
|
||||
get hasAvatar(): boolean {
|
||||
return !!this.avatarUrl;
|
||||
// Buffer is already base64 encoded in ViewData
|
||||
this.bufferBase64 = viewData.buffer;
|
||||
|
||||
// Derive content type label using Display Object
|
||||
this.contentTypeLabel = AvatarDisplay.formatContentType(viewData.contentType);
|
||||
|
||||
// Derive validity check using Display Object
|
||||
this.hasValidData = AvatarDisplay.hasValidData(viewData.buffer, viewData.contentType);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user