ozon-task/graph/model/data.go

75 lines
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
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,
},
}
)
2024-06-24 23:34:10 +00:00
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"`
2024-06-24 23:34:10 +00:00
}
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"`
2024-06-24 23:34:10 +00:00
Comments []*Comment `json:"comments" gorm:"foreignKey:PostID"`
AllowComments bool `json:"allowComments" gorm:"column:allow_comments"`
2024-06-24 23:34:10 +00:00
}
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),
}
}