diff --git a/pkg/models/comments.go b/pkg/models/comments.go index cf1d37b..ad2ef33 100644 --- a/pkg/models/comments.go +++ b/pkg/models/comments.go @@ -3,12 +3,13 @@ package models type Comment struct { PostBase - Content string `json:"content"` - Hashtags []Tag `json:"tags" gorm:"many2many:comment_tags"` - Categories []Category `json:"categories" gorm:"many2many:comment_categories"` - Reactions []Reaction `json:"reactions"` - ReplyID *uint `json:"reply_id"` - ReplyTo *Comment `json:"reply_to" gorm:"foreignKey:ReplyID"` + Content string `json:"content"` + Hashtags []Tag `json:"tags" gorm:"many2many:comment_tags"` + Categories []Category `json:"categories" gorm:"many2many:comment_categories"` + Reactions []Reaction `json:"reactions"` + Attachments []Attachment `json:"attachments"` + ReplyID *uint `json:"reply_id"` + ReplyTo *Comment `json:"reply_to" gorm:"foreignKey:ReplyID"` ArticleID *uint `json:"article_id"` MomentID *uint `json:"moment_id"` diff --git a/pkg/server/comments_api.go b/pkg/server/comments_api.go index b04860c..7b0798f 100644 --- a/pkg/server/comments_api.go +++ b/pkg/server/comments_api.go @@ -57,11 +57,12 @@ func createComment(c *fiber.Ctx) error { user := c.Locals("principal").(models.Account) var data struct { - Content string `json:"content" form:"content" validate:"required"` - PublishedAt *time.Time `json:"published_at" form:"published_at"` - Hashtags []models.Tag `json:"hashtags" form:"hashtags"` - Categories []models.Category `json:"categories" form:"categories"` - ReplyTo uint `json:"reply_to" form:"reply_to"` + Content string `json:"content" form:"content" validate:"required"` + PublishedAt *time.Time `json:"published_at" form:"published_at"` + Hashtags []models.Tag `json:"hashtags" form:"hashtags"` + Categories []models.Category `json:"categories" form:"categories"` + Attachments []models.Attachment `json:"attachments" form:"attachments"` + ReplyTo uint `json:"reply_to" form:"reply_to"` } if err := BindAndValidate(c, &data); err != nil { @@ -74,9 +75,10 @@ func createComment(c *fiber.Ctx) error { PublishedAt: data.PublishedAt, AuthorID: user.ID, }, - Hashtags: data.Hashtags, - Categories: data.Categories, - Content: data.Content, + Hashtags: data.Hashtags, + Categories: data.Categories, + Attachments: data.Attachments, + Content: data.Content, } postType := c.Params("postType") diff --git a/pkg/server/moments_api.go b/pkg/server/moments_api.go index 6150e10..8adfdb8 100644 --- a/pkg/server/moments_api.go +++ b/pkg/server/moments_api.go @@ -100,7 +100,7 @@ func editMoment(c *fiber.Ctx) error { return err } - var item *models.Moment + var item *models.Comment if err := database.C.Where(models.Comment{ PostBase: models.PostBase{ BaseModel: models.BaseModel{ID: uint(id)},