BLOG-118 Fix to allow nullable published_time to support unpublished posts #121
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "BLOG-118_fix_error_when_access_unpublished_post"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
This PR updates the application to handle posts that may not have a publication date (e.g., drafts) by making the
published_time
field optional across the entire post feature stack.This ensures that draft posts can be processed and rendered without causing errors, and prevents search engine metadata from being generated for content that is not yet published.
Key Changes:
DTO & Schema (
postInfoResponseDto.ts
):PostInfoResponseSchema
has been updated to markpublished_time
as.nullable()
.PostInfoResponseDto
class now correctly handles anull
value from the API, mapping it toDate | null
.Domain Entity (
postInfo.ts
):PostInfo
entity'spublishedTime
property is now typed asDate | null
to reflect the business logic that a post may be unpublished.View Model (
postInfoViewModel.ts
):publishedTime
to beDate | null
.isPublished
boolean getter for convenient conditional logic in the UI.formattedPublishedTime
getter now returnsstring | null
.dehydrate
/rehydrate
) has been updated to correctly handle the nullablepublishedTime
.UI Component (
PostContentPage.svelte
):isPublished
flag to conditionally render the<StructuredData>
component for SEO. This ensures that structured data is only included for posts that have been officially published.Package Changes
No response
Screenshots
No response
Reference
Resolves #118
Checklist
null
/improve
PR Code Suggestions ✨
Add null check for date property
The
datePublished
prop of theStructuredData
component likely expects aDate
object,but
state.data.info.publishedTime
is typed asDate | null
. Although there's anisPublished
check, it's safer to explicitly verifypublishedTime
is not null beforepassing it. This prevents potential runtime errors if
isPublished
is true butpublishedTime
is unexpectedlynull
.frontend/src/lib/post/framework/ui/PostContentPage.svelte [25-32]
Suggestion importance[1-10]: 8
__
Why: The suggestion correctly identifies that
state.data.info.publishedTime
can beDate | null
. Adding an explicit null check (&& state.data.info.publishedTime
) before passing it toStructuredData
prevents potential runtime errors, even with theisPublished
flag, and correctly removes the non-null assertion operator (!
).Ignore.