Add comment functionality.

This commit is contained in:
2025-05-13 17:11:48 +08:00
parent 545432b4f1
commit 0dd2143664
16 changed files with 406 additions and 53 deletions

31
server/model/comment.go Normal file
View File

@@ -0,0 +1,31 @@
package model
import (
"gorm.io/gorm"
"time"
)
type Comment struct {
gorm.Model
Content string `gorm:"not null"`
ResourceID uint `gorm:"not null"`
UserID uint `gorm:"not null"`
User User `gorm:"foreignKey:UserID"`
Resource Resource `gorm:"foreignKey:ResourceID"`
}
type CommentView struct {
ID uint `json:"id"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
User UserView `json:"user"`
}
func (c *Comment) ToView() *CommentView {
return &CommentView{
ID: c.ID,
Content: c.Content,
CreatedAt: c.CreatedAt,
User: c.User.ToView(),
}
}