blog/frontend/src/lib/post/adapter/presenter/postInfoViewModel.ts
SquidSpirit 901d367d9d
Some checks failed
Frontend CI / build (push) Failing after 52s
BLOG-45 fix: trivial style
2025-07-24 04:55:55 +08:00

43 lines
1.2 KiB
TypeScript

import { LabelViewModel } from '$lib/post/adapter/presenter/labelViewModel';
import type { PostInfo } from '$lib/post/domain/entity/postInfo';
export class PostInfoViewModel {
readonly id: number;
readonly title: string;
readonly description: string;
readonly previewImageUrl: URL;
readonly labels: readonly LabelViewModel[];
readonly publishedTime: Date;
private constructor(props: {
id: number;
title: string;
description: string;
previewImageUrl: URL;
labels: readonly LabelViewModel[];
publishedTime: Date;
}) {
this.id = props.id;
this.title = props.title;
this.description = props.description;
this.previewImageUrl = props.previewImageUrl;
this.labels = props.labels;
this.publishedTime = props.publishedTime;
}
static fromEntity(postInfo: PostInfo): PostInfoViewModel {
return new PostInfoViewModel({
id: postInfo.id,
title: postInfo.title,
description: postInfo.description,
previewImageUrl: postInfo.previewImageUrl,
labels: postInfo.labels.map((label) => LabelViewModel.fromEntity(label)),
publishedTime: postInfo.publishedTime
});
}
get formattedPublishedTime(): string {
return this.publishedTime.toISOString().slice(0, 10);
}
}