diff --git a/frontend/src/lib/post/adapter/gateway/postInfoResponseDto.ts b/frontend/src/lib/post/adapter/gateway/postInfoResponseDto.ts index 91737ff..861244b 100644 --- a/frontend/src/lib/post/adapter/gateway/postInfoResponseDto.ts +++ b/frontend/src/lib/post/adapter/gateway/postInfoResponseDto.ts @@ -8,7 +8,7 @@ export const PostInfoResponseSchema = z.object({ description: z.string(), preview_image_url: z.url(), labels: z.array(LabelResponseSchema), - published_time: z.iso.datetime({ offset: true }) + published_time: z.iso.datetime({ offset: true }).nullable() }); export class PostInfoResponseDto { @@ -17,7 +17,7 @@ export class PostInfoResponseDto { readonly description: string; readonly previewImageUrl: URL; readonly labels: readonly LabelResponseDto[]; - readonly publishedTime: Date; + readonly publishedTime: Date | null; private constructor(props: { id: number; @@ -25,7 +25,7 @@ export class PostInfoResponseDto { description: string; previewImageUrl: URL; labels: LabelResponseDto[]; - publishedTime: Date; + publishedTime: Date | null; }) { this.id = props.id; this.title = props.title; @@ -37,13 +37,19 @@ export class PostInfoResponseDto { static fromJson(json: unknown): PostInfoResponseDto { const parsedJson = PostInfoResponseSchema.parse(json); + + let published_time: Date | null = null; + if (parsedJson.published_time !== null) { + published_time = new Date(parsedJson.published_time); + } + return new PostInfoResponseDto({ id: parsedJson.id, title: parsedJson.title, description: parsedJson.description, previewImageUrl: new URL(parsedJson.preview_image_url), labels: parsedJson.labels.map((label) => LabelResponseDto.fromJson(label)), - publishedTime: new Date(parsedJson.published_time) + publishedTime: published_time }); } diff --git a/frontend/src/lib/post/adapter/presenter/postInfoViewModel.ts b/frontend/src/lib/post/adapter/presenter/postInfoViewModel.ts index 670acb7..7fcfcbd 100644 --- a/frontend/src/lib/post/adapter/presenter/postInfoViewModel.ts +++ b/frontend/src/lib/post/adapter/presenter/postInfoViewModel.ts @@ -10,7 +10,7 @@ export class PostInfoViewModel { readonly description: string; readonly previewImageUrl: URL; readonly labels: readonly LabelViewModel[]; - readonly publishedTime: Date; + readonly publishedTime: Date | null; private constructor(props: { id: number; @@ -18,7 +18,7 @@ export class PostInfoViewModel { description: string; previewImageUrl: URL; labels: readonly LabelViewModel[]; - publishedTime: Date; + publishedTime: Date | null; }) { this.id = props.id; this.title = props.title; @@ -40,18 +40,27 @@ export class PostInfoViewModel { } static rehydrate(props: DehydratedPostInfoProps): PostInfoViewModel { + let publishedTime: Date | null = null; + if (props.publishedTime !== null) { + publishedTime = new Date(props.publishedTime); + } + return new PostInfoViewModel({ id: props.id, title: props.title, description: props.description, previewImageUrl: new URL(props.previewImageUrl), labels: props.labels.map((label) => LabelViewModel.rehydrate(label)), - publishedTime: new Date(props.publishedTime) + publishedTime: publishedTime }); } - get formattedPublishedTime(): string { - return this.publishedTime.toISOString().slice(0, 10); + get isPublished(): boolean { + return this.publishedTime !== null; + } + + get formattedPublishedTime(): string | null { + return this.publishedTime?.toISOString().slice(0, 10) ?? null; } dehydrate(): DehydratedPostInfoProps { @@ -61,7 +70,7 @@ export class PostInfoViewModel { description: this.description, previewImageUrl: this.previewImageUrl.href, labels: this.labels.map((label) => label.dehydrate()), - publishedTime: this.publishedTime.getTime() + publishedTime: this.publishedTime?.getTime() ?? null }; } } @@ -72,5 +81,5 @@ export interface DehydratedPostInfoProps { description: string; previewImageUrl: string; labels: DehydratedLabelProps[]; - publishedTime: number; + publishedTime: number | null; } diff --git a/frontend/src/lib/post/domain/entity/postInfo.ts b/frontend/src/lib/post/domain/entity/postInfo.ts index 129ffe2..002c788 100644 --- a/frontend/src/lib/post/domain/entity/postInfo.ts +++ b/frontend/src/lib/post/domain/entity/postInfo.ts @@ -6,7 +6,7 @@ export class PostInfo { readonly description: string; readonly previewImageUrl: URL; readonly labels: readonly Label[]; - readonly publishedTime: Date; + readonly publishedTime: Date | null; constructor(props: { id: number; @@ -14,7 +14,7 @@ export class PostInfo { description: string; previewImageUrl: URL; labels: readonly Label[]; - publishedTime: Date; + publishedTime: Date | null; }) { this.id = props.id; this.title = props.title; diff --git a/frontend/src/lib/post/framework/ui/PostContentPage.svelte b/frontend/src/lib/post/framework/ui/PostContentPage.svelte index 8bd038a..59ca863 100644 --- a/frontend/src/lib/post/framework/ui/PostContentPage.svelte +++ b/frontend/src/lib/post/framework/ui/PostContentPage.svelte @@ -22,15 +22,17 @@