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,