diff --git a/pkg/server/posts_api.go b/pkg/server/posts_api.go index 26f6418..6b43744 100644 --- a/pkg/server/posts_api.go +++ b/pkg/server/posts_api.go @@ -181,12 +181,13 @@ func editPost(c *fiber.Ctx) error { id, _ := c.ParamsInt("postId", 0) var data struct { - Alias string `json:"alias" validate:"required"` - Title string `json:"title"` - Content string `json:"content" validate:"required"` - PublishedAt *time.Time `json:"published_at"` - Tags []models.Tag `json:"tags"` - Categories []models.Category `json:"categories"` + Alias string `json:"alias" validate:"required"` + Title string `json:"title"` + Content string `json:"content" validate:"required"` + PublishedAt *time.Time `json:"published_at"` + Tags []models.Tag `json:"tags"` + Categories []models.Category `json:"categories"` + Attachments []models.Attachment `json:"attachments"` } if err := BindAndValidate(c, &data); err != nil { @@ -209,6 +210,7 @@ func editPost(c *fiber.Ctx) error { data.PublishedAt, data.Categories, data.Tags, + data.Attachments, ) if err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) diff --git a/pkg/services/posts.go b/pkg/services/posts.go index af48909..01f99ed 100644 --- a/pkg/services/posts.go +++ b/pkg/services/posts.go @@ -214,6 +214,7 @@ func EditPost( publishedAt *time.Time, categories []models.Category, tags []models.Tag, + attachments []models.Attachment, ) (models.Post, error) { var err error for idx, category := range categories { @@ -237,6 +238,9 @@ func EditPost( post.Title = title post.Content = content post.PublishedAt = *publishedAt + post.Tags = tags + post.Categories = categories + post.Attachments = attachments err = database.C.Save(&post).Error