🐛 Try to fix post has no published at

This commit is contained in:
LittleSheep 2024-07-29 11:47:02 +08:00
parent 7ae1f8021b
commit 0519d99bbd
3 changed files with 8 additions and 4 deletions

View File

@ -65,6 +65,10 @@ func createArticle(c *fiber.Ctx) error {
AuthorID: user.ID, AuthorID: user.ID,
} }
if item.PublishedAt == nil {
item.PublishedAt = lo.ToPtr(time.Now())
}
if data.Visibility != nil { if data.Visibility != nil {
item.Visibility = *data.Visibility item.Visibility = *data.Visibility
} else { } else {

View File

@ -67,6 +67,10 @@ func createStory(c *fiber.Ctx) error {
AuthorID: user.ID, AuthorID: user.ID,
} }
if item.PublishedAt == nil {
item.PublishedAt = lo.ToPtr(time.Now())
}
if data.Visibility != nil { if data.Visibility != nil {
item.Visibility = *data.Visibility item.Visibility = *data.Visibility
} else { } else {

View File

@ -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...") log.Debug().Msg("Saving post record into database...")
if err := database.C.Save(&item).Error; err != nil { if err := database.C.Save(&item).Error; err != nil {
return item, err return item, err