19 lines
560 B
Go
19 lines
560 B
Go
package models
|
|
|
|
type Comment struct {
|
|
Model
|
|
Key string `gorm:"unique_index; not null" json:"key"`
|
|
Content string `json:"content"`
|
|
UserId int `json:"user_id"`
|
|
User User `json:"user"`
|
|
NoteKey string `json:"note_key"`
|
|
Praise int `gorm:"default:0" json:"praise"`
|
|
}
|
|
|
|
func QueryCommentByNoteKey(noteKey string) (comments []*Comment, err error) {
|
|
return comments, db.Preload("User").Where("`note_key` = ?", noteKey).Order("`updated_at` desc").Find(&comments).Error
|
|
}
|
|
|
|
func SaveComment(comment *Comment) (err error) {
|
|
return db.Save(comment).Error
|
|
} |