From c8d55d0b2c227d5c51aebf899cbb90a836b8c5ae Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 25 Jul 2024 22:41:18 +0800 Subject: [PATCH] :wheelchair: Edit post will auto help user correct data --- pkg/internal/server/api/articles_api.go | 5 +++-- pkg/internal/server/api/stories_api.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/internal/server/api/articles_api.go b/pkg/internal/server/api/articles_api.go index 774d0a4..ccb4904 100644 --- a/pkg/internal/server/api/articles_api.go +++ b/pkg/internal/server/api/articles_api.go @@ -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 { diff --git a/pkg/internal/server/api/stories_api.go b/pkg/internal/server/api/stories_api.go index 4d9010d..a05e758 100644 --- a/pkg/internal/server/api/stories_api.go +++ b/pkg/internal/server/api/stories_api.go @@ -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