mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Add comment functionality.
This commit is contained in:
31
server/model/comment.go
Normal file
31
server/model/comment.go
Normal 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(),
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user