package model import ( "time" "gorm.io/gorm" ) const CommentLengthLimit = 2000 var ( EmptyCommentsConnection = CommentsConnection{ Edges: make([]*CommentsEdge, 0), PageInfo: &PageInfo{ StartCursor: 0, EndCursor: 0, HasNextPage: false, }, } EmptyPostsConnections = PostsConnection{ Edges: make([]*PostsEdge, 0), PageInfo: &PageInfo{ StartCursor: 0, EndCursor: 0, HasNextPage: false, }, } ) type Comment struct { // db fields ID uint `json:"id" gorm:"primarykey;column:id"` CreatedAt time.Time `gorm:"column:created_at"` UpdatedAt time.Time `gorm:"column:updated_at"` DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at"` RootComment bool `gorm:"column:root"` PostID uint `json:"post_id" gorm:"column:post_id"` Author string `json:"author" gorm:"column:author"` Contents string `json:"contents" gorm:"column:contents"` Replies []*Comment `json:"replies" gorm:"many2many:comment_replies"` } type Post struct { // db fields ID uint `json:"id" gorm:"primarykey;column:id"` CreatedAt time.Time `gorm:"column:created_at"` UpdatedAt time.Time `gorm:"column:updated_at"` DeletedAt gorm.DeletedAt `gorm:"index;column:deleted_at"` Title string `json:"title" gorm:"column:title"` Author string `json:"author" gorm:"column:author"` Contents string `json:"contents" gorm:"column:contents"` Comments []*Comment `json:"comments" gorm:"foreignKey:PostID"` AllowComments bool `json:"allowComments" gorm:"column:allow_comments"` } func PostFromInput(input *PostInput) *Post { return &Post{ Author: input.Author, Title: input.Title, Contents: input.Contents, AllowComments: input.AllowComments, Comments: make([]*Comment, 0), } } func CommentFromInput(input *CommentInput) *Comment { return &Comment{ Author: input.Author, Contents: input.Contents, Replies: make([]*Comment, 0), } }