♻️ 一切尽在帖子表 #4
@ -30,6 +30,7 @@ type Post struct {
|
|||||||
|
|
||||||
IsDraft bool `json:"is_draft"`
|
IsDraft bool `json:"is_draft"`
|
||||||
PublishedAt *time.Time `json:"published_at"`
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
PublishedUntil *time.Time `json:"published_until"`
|
||||||
|
|
||||||
AuthorID uint `json:"author_id"`
|
AuthorID uint `json:"author_id"`
|
||||||
Author Account `json:"author"`
|
Author Account `json:"author"`
|
||||||
|
@ -23,11 +23,12 @@ func createArticle(c *fiber.Ctx) error {
|
|||||||
Description *string `json:"description" validate:"max=2048"`
|
Description *string `json:"description" validate:"max=2048"`
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
Attachments []uint `json:"attachments"`
|
Attachments []uint `json:"attachments"`
|
||||||
PublishedAt *time.Time `json:"published_at"`
|
|
||||||
IsDraft bool `json:"is_draft"`
|
|
||||||
RealmAlias *string `json:"realm"`
|
|
||||||
Tags []models.Tag `json:"tags"`
|
Tags []models.Tag `json:"tags"`
|
||||||
Categories []models.Category `json:"categories"`
|
Categories []models.Category `json:"categories"`
|
||||||
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
PublishedUntil *time.Time `json:"published_until"`
|
||||||
|
IsDraft bool `json:"is_draft"`
|
||||||
|
RealmAlias *string `json:"realm"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -52,6 +53,7 @@ func createArticle(c *fiber.Ctx) error {
|
|||||||
Categories: data.Categories,
|
Categories: data.Categories,
|
||||||
IsDraft: data.IsDraft,
|
IsDraft: data.IsDraft,
|
||||||
PublishedAt: data.PublishedAt,
|
PublishedAt: data.PublishedAt,
|
||||||
|
PublishedUntil: data.PublishedUntil,
|
||||||
AuthorID: user.ID,
|
AuthorID: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,10 +87,11 @@ func editArticle(c *fiber.Ctx) error {
|
|||||||
Description *string `json:"description" validate:"max=2048"`
|
Description *string `json:"description" validate:"max=2048"`
|
||||||
Content string `json:"content" validate:"required"`
|
Content string `json:"content" validate:"required"`
|
||||||
Attachments []uint `json:"attachments"`
|
Attachments []uint `json:"attachments"`
|
||||||
IsDraft bool `json:"is_draft"`
|
|
||||||
PublishedAt *time.Time `json:"published_at"`
|
|
||||||
Tags []models.Tag `json:"tags"`
|
Tags []models.Tag `json:"tags"`
|
||||||
Categories []models.Category `json:"categories"`
|
Categories []models.Category `json:"categories"`
|
||||||
|
IsDraft bool `json:"is_draft"`
|
||||||
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
PublishedUntil *time.Time `json:"published_until"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -114,10 +117,11 @@ func editArticle(c *fiber.Ctx) error {
|
|||||||
_ = jsoniter.Unmarshal(rawBody, &bodyMapping)
|
_ = jsoniter.Unmarshal(rawBody, &bodyMapping)
|
||||||
|
|
||||||
item.Body = bodyMapping
|
item.Body = bodyMapping
|
||||||
item.IsDraft = data.IsDraft
|
|
||||||
item.PublishedAt = data.PublishedAt
|
|
||||||
item.Tags = data.Tags
|
item.Tags = data.Tags
|
||||||
item.Categories = data.Categories
|
item.Categories = data.Categories
|
||||||
|
item.IsDraft = data.IsDraft
|
||||||
|
item.PublishedAt = data.PublishedAt
|
||||||
|
item.PublishedUntil = data.PublishedUntil
|
||||||
|
|
||||||
if item, err := services.EditPost(item); err != nil {
|
if item, err := services.EditPost(item); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
@ -26,6 +26,7 @@ func createStory(c *fiber.Ctx) error {
|
|||||||
Tags []models.Tag `json:"tags"`
|
Tags []models.Tag `json:"tags"`
|
||||||
Categories []models.Category `json:"categories"`
|
Categories []models.Category `json:"categories"`
|
||||||
PublishedAt *time.Time `json:"published_at"`
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
PublishedUntil *time.Time `json:"published_until"`
|
||||||
IsDraft bool `json:"is_draft"`
|
IsDraft bool `json:"is_draft"`
|
||||||
RealmAlias *string `json:"realm"`
|
RealmAlias *string `json:"realm"`
|
||||||
ReplyTo *uint `json:"reply_to"`
|
ReplyTo *uint `json:"reply_to"`
|
||||||
@ -52,8 +53,9 @@ func createStory(c *fiber.Ctx) error {
|
|||||||
Body: bodyMapping,
|
Body: bodyMapping,
|
||||||
Tags: data.Tags,
|
Tags: data.Tags,
|
||||||
Categories: data.Categories,
|
Categories: data.Categories,
|
||||||
IsDraft: data.IsDraft,
|
|
||||||
PublishedAt: data.PublishedAt,
|
PublishedAt: data.PublishedAt,
|
||||||
|
PublishedUntil: data.PublishedUntil,
|
||||||
|
IsDraft: data.IsDraft,
|
||||||
AuthorID: user.ID,
|
AuthorID: user.ID,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,10 +106,11 @@ func editStory(c *fiber.Ctx) error {
|
|||||||
Content string `json:"content" validate:"required,max=4096"`
|
Content string `json:"content" validate:"required,max=4096"`
|
||||||
Location *string `json:"location" validate:"max=2048"`
|
Location *string `json:"location" validate:"max=2048"`
|
||||||
Attachments []uint `json:"attachments"`
|
Attachments []uint `json:"attachments"`
|
||||||
IsDraft bool `json:"is_draft"`
|
|
||||||
PublishedAt *time.Time `json:"published_at"`
|
|
||||||
Tags []models.Tag `json:"tags"`
|
Tags []models.Tag `json:"tags"`
|
||||||
Categories []models.Category `json:"categories"`
|
Categories []models.Category `json:"categories"`
|
||||||
|
PublishedAt *time.Time `json:"published_at"`
|
||||||
|
PublishedUntil *time.Time `json:"published_until"`
|
||||||
|
IsDraft bool `json:"is_draft"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := exts.BindAndValidate(c, &data); err != nil {
|
if err := exts.BindAndValidate(c, &data); err != nil {
|
||||||
@ -134,10 +137,11 @@ func editStory(c *fiber.Ctx) error {
|
|||||||
_ = jsoniter.Unmarshal(rawBody, &bodyMapping)
|
_ = jsoniter.Unmarshal(rawBody, &bodyMapping)
|
||||||
|
|
||||||
item.Body = bodyMapping
|
item.Body = bodyMapping
|
||||||
item.IsDraft = data.IsDraft
|
|
||||||
item.PublishedAt = data.PublishedAt
|
|
||||||
item.Tags = data.Tags
|
item.Tags = data.Tags
|
||||||
item.Categories = data.Categories
|
item.Categories = data.Categories
|
||||||
|
item.PublishedAt = data.PublishedAt
|
||||||
|
item.PublishedUntil = data.PublishedUntil
|
||||||
|
item.IsDraft = data.IsDraft
|
||||||
|
|
||||||
if item, err := services.EditPost(item); err != nil {
|
if item, err := services.EditPost(item); err != nil {
|
||||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
@ -44,7 +44,9 @@ func FilterPostReply(tx *gorm.DB, replyTo ...uint) *gorm.DB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithPublishedAt(tx *gorm.DB, date time.Time) *gorm.DB {
|
func FilterPostWithPublishedAt(tx *gorm.DB, date time.Time) *gorm.DB {
|
||||||
return tx.Where("published_at <= ? OR published_at IS NULL", date)
|
return tx.
|
||||||
|
Where("published_at <= ? OR published_at IS NULL", date).
|
||||||
|
Where("published_until > ? OR published_until IS NULL", date)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FilterPostWithAuthorDraft(tx *gorm.DB, uid uint) *gorm.DB {
|
func FilterPostWithAuthorDraft(tx *gorm.DB, uid uint) *gorm.DB {
|
||||||
|
Loading…
Reference in New Issue
Block a user