🐛 Fix edit draft state wont set published at

This commit is contained in:
LittleSheep 2024-07-25 22:39:19 +08:00
parent 2f8f799926
commit f49cd3a892
2 changed files with 14 additions and 2 deletions

View File

@ -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,

View File

@ -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,