ozon-task/graph/model/data.go
erius e0aa12b126 Separated graphql schema into multiple files and moved them to graph/schema dir, update the gqlgen.yml accordingly
Removed unnecesary bindings for ID and Int in gqlgen.yml
Minor changes to Makefile docker-clean target
Reduced docker-compose postgres healthcheck interval for faster local db connections
Added pagination to graphql schema, the paginated queries are WIP
Removed unneeded fields from the model structs
Added allowComment check when adding comments
Switched gorm logger to Info mode
App now panics if the specified APP_STORAGE in env doesn't exist
Reworked database methods, still barely working and are WIP
2024-06-26 04:45:04 +03:00

54 lines
1.2 KiB
Go

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"`
}
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),
}
}
func CommentFromInput(input *CommentInput) *Comment {
return &Comment{
Author: input.Author,
Contents: input.Contents,
Replies: make([]*Comment, 0),
}
}