From f49cd3a8928e8f55769932b04ca625aae15ad15f Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 25 Jul 2024 22:39:19 +0800 Subject: [PATCH] :bug: Fix edit draft state wont set published at --- pkg/internal/server/api/articles_api.go | 8 +++++++- pkg/internal/server/api/stories_api.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/internal/server/api/articles_api.go b/pkg/internal/server/api/articles_api.go index 00d874a..774d0a4 100644 --- a/pkg/internal/server/api/articles_api.go +++ b/pkg/internal/server/api/articles_api.go @@ -2,6 +2,8 @@ package api import ( "fmt" + "time" + "git.solsynth.dev/hydrogen/interactive/pkg/internal/database" "git.solsynth.dev/hydrogen/interactive/pkg/internal/gap" "git.solsynth.dev/hydrogen/interactive/pkg/internal/models" @@ -9,7 +11,7 @@ import ( "git.solsynth.dev/hydrogen/interactive/pkg/internal/services" "github.com/gofiber/fiber/v2" jsoniter "github.com/json-iterator/go" - "time" + "github.com/samber/lo" ) func createArticle(c *fiber.Ctx) error { @@ -107,6 +109,10 @@ func editArticle(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusNotFound, err.Error()) } + if item.IsDraft && !data.IsDraft { + item.PublishedAt = lo.ToPtr(time.Now()) + } + body := models.PostArticleBody{ Title: data.Title, Content: data.Content, diff --git a/pkg/internal/server/api/stories_api.go b/pkg/internal/server/api/stories_api.go index 4a85378..4d9010d 100644 --- a/pkg/internal/server/api/stories_api.go +++ b/pkg/internal/server/api/stories_api.go @@ -2,6 +2,8 @@ package api import ( "fmt" + "time" + "git.solsynth.dev/hydrogen/interactive/pkg/internal/database" "git.solsynth.dev/hydrogen/interactive/pkg/internal/gap" "git.solsynth.dev/hydrogen/interactive/pkg/internal/models" @@ -9,7 +11,7 @@ import ( "git.solsynth.dev/hydrogen/interactive/pkg/internal/services" "github.com/gofiber/fiber/v2" jsoniter "github.com/json-iterator/go" - "time" + "github.com/samber/lo" ) func createStory(c *fiber.Ctx) error { @@ -126,6 +128,10 @@ func editStory(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusNotFound, err.Error()) } + if item.IsDraft && !data.IsDraft { + item.PublishedAt = lo.ToPtr(time.Now()) + } + body := models.PostStoryBody{ Title: data.Title, Content: data.Content,