Edit post will auto help user correct data

This commit is contained in:
LittleSheep 2024-07-25 22:41:18 +08:00
parent f49cd3a892
commit c8d55d0b2c
2 changed files with 6 additions and 4 deletions

View File

@ -109,8 +109,10 @@ func editArticle(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
if item.IsDraft && !data.IsDraft {
if item.IsDraft && !data.IsDraft && data.PublishedAt == nil {
item.PublishedAt = lo.ToPtr(time.Now())
} else {
item.PublishedAt = data.PublishedAt
}
body := models.PostArticleBody{
@ -128,7 +130,6 @@ func editArticle(c *fiber.Ctx) error {
item.Tags = data.Tags
item.Categories = data.Categories
item.IsDraft = data.IsDraft
item.PublishedAt = data.PublishedAt
item.PublishedUntil = data.PublishedUntil
if item, err := services.EditPost(item); err != nil {

View File

@ -128,8 +128,10 @@ func editStory(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
if item.IsDraft && !data.IsDraft {
if item.IsDraft && !data.IsDraft && data.PublishedAt == nil {
item.PublishedAt = lo.ToPtr(time.Now())
} else {
item.PublishedAt = data.PublishedAt
}
body := models.PostStoryBody{
@ -147,7 +149,6 @@ func editStory(c *fiber.Ctx) error {
item.Language = services.DetectLanguage(data.Content)
item.Tags = data.Tags
item.Categories = data.Categories
item.PublishedAt = data.PublishedAt
item.PublishedUntil = data.PublishedUntil
item.IsDraft = data.IsDraft