2024-06-24 23:34:10 +00:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
const CommentLengthLimit = 2000
|
|
|
|
|
|
|
|
type Comment struct {
|
|
|
|
// db fields
|
|
|
|
ID uint `json:"id" gorm:"primarykey"`
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
2024-06-26 01:45:04 +00:00
|
|
|
PostID uint `json:"post_id"`
|
|
|
|
Author string `json:"author"`
|
|
|
|
Contents string `json:"contents"`
|
|
|
|
Replies []*Comment `json:"replies" gorm:"many2many:comment_replies"`
|
2024-06-24 23:34:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Post struct {
|
|
|
|
// db fields
|
|
|
|
ID uint `json:"id" gorm:"primarykey"`
|
|
|
|
CreatedAt time.Time
|
|
|
|
UpdatedAt time.Time
|
|
|
|
DeletedAt gorm.DeletedAt `gorm:"index"`
|
|
|
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
Author string `json:"author"`
|
|
|
|
Contents string `json:"contents"`
|
|
|
|
Comments []*Comment `json:"comments" gorm:"foreignKey:PostID"`
|
|
|
|
AllowComments bool `json:"allowComments"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func PostFromInput(input *PostInput) *Post {
|
|
|
|
return &Post{
|
|
|
|
Author: input.Author,
|
|
|
|
Title: input.Title,
|
|
|
|
Contents: input.Contents,
|
|
|
|
AllowComments: input.AllowComments,
|
2024-06-26 01:45:04 +00:00
|
|
|
Comments: make([]*Comment, 0),
|
2024-06-24 23:34:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func CommentFromInput(input *CommentInput) *Comment {
|
|
|
|
return &Comment{
|
|
|
|
Author: input.Author,
|
|
|
|
Contents: input.Contents,
|
|
|
|
Replies: make([]*Comment, 0),
|
|
|
|
}
|
|
|
|
}
|