diff --git a/pkg/internal/server/api/articles_api.go b/pkg/internal/server/api/articles_api.go index 4990ede..0eb1902 100644 --- a/pkg/internal/server/api/articles_api.go +++ b/pkg/internal/server/api/articles_api.go @@ -65,6 +65,10 @@ func createArticle(c *fiber.Ctx) error { AuthorID: user.ID, } + if item.PublishedAt == nil { + item.PublishedAt = lo.ToPtr(time.Now()) + } + if data.Visibility != nil { item.Visibility = *data.Visibility } else { diff --git a/pkg/internal/server/api/stories_api.go b/pkg/internal/server/api/stories_api.go index abb165c..1a48702 100644 --- a/pkg/internal/server/api/stories_api.go +++ b/pkg/internal/server/api/stories_api.go @@ -67,6 +67,10 @@ func createStory(c *fiber.Ctx) error { AuthorID: user.ID, } + if item.PublishedAt == nil { + item.PublishedAt = lo.ToPtr(time.Now()) + } + if data.Visibility != nil { item.Visibility = *data.Visibility } else { diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index 00f0873..866ff44 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -240,10 +240,6 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) { } } - if !item.IsDraft && item.PublishedAt == nil { - item.PublishedAt = lo.ToPtr(time.Now()) - } - log.Debug().Msg("Saving post record into database...") if err := database.C.Save(&item).Error; err != nil { return item, err