blog/frontend/src/lib/post/adapter/presenter/labelViewModel.ts
SquidSpirit a73c3c3354
Some checks failed
Frontend CI / build (push) Failing after 46s
BLOG-45 feat: improve efficiency with ssr
2025-07-24 08:03:15 +08:00

48 lines
1.0 KiB
TypeScript

import {
ColorViewModel,
type DehydratedColorProps
} from '$lib/post/adapter/presenter/colorViewModel';
import type { Label } from '$lib/post/domain/entity/label';
export class LabelViewModel {
readonly id: number;
readonly name: string;
readonly color: ColorViewModel;
private constructor(props: { id: number; name: string; color: ColorViewModel }) {
this.id = props.id;
this.name = props.name;
this.color = props.color;
}
static fromEntity(label: Label): LabelViewModel {
return new LabelViewModel({
id: label.id,
name: label.name,
color: ColorViewModel.fromEntity(label.color)
});
}
static rehydrate(props: DehydratedLabelProps): LabelViewModel {
return new LabelViewModel({
id: props.id,
name: props.name,
color: ColorViewModel.rehydrate(props.color)
});
}
dehydrate(): DehydratedLabelProps {
return {
id: this.id,
name: this.name,
color: this.color.dehydrate()
};
}
}
export interface DehydratedLabelProps {
id: number;
name: string;
color: DehydratedColorProps;
}