erius
e0aa12b126
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
54 lines
1.2 KiB
Go
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),
|
|
}
|
|
}
|