31 lines
1.2 KiB
Go
31 lines
1.2 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// PostComment represents a comment on a post.
|
|
type PostComment struct {
|
|
ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();primaryKey" json:"id"`
|
|
UserID uuid.UUID `gorm:"not null" json:"user_id"`
|
|
User User `gorm:"foreignKey:UserID" json:"user"`
|
|
PostID uuid.UUID `gorm:"not null" json:"post_id"`
|
|
Post Post `gorm:"foreignKey:PostID" json:"post"`
|
|
Title string `gorm:"type:varchar(254);not null" json:"title"`
|
|
Body string `gorm:"type:text;not null" json:"body"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
IsActive bool `gorm:"default:true" json:"is_active"`
|
|
Slug string `gorm:"type:varchar(250);uniqueIndex:idx_post_comment_slug_parent;not null" json:"slug"`
|
|
ParentID *uuid.UUID `gorm:"uniqueIndex:idx_post_comment_slug_parent" json:"parent_id,omitempty"`
|
|
Parent *PostComment `gorm:"foreignKey:ParentID" json:"parent,omitempty"`
|
|
Children []PostComment `gorm:"foreignKey:ParentID" json:"children,omitempty"`
|
|
}
|
|
|
|
// TableName overrides the table name used by PostComment.
|
|
func (PostComment) TableName() string {
|
|
return "post_comments"
|
|
}
|