ozon-task/graph/model/data.go

55 lines
1.2 KiB
Go
Raw Normal View History

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"`
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,
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),
}
}