models

package
v0.0.0-...-c9b56a8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2021 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateThread

func CreateThread(tx *gorm.DB, thread *Thread) error

func NodeExists

func NodeExists(tx *gorm.DB, nodeID base.ID) bool

func ThreadExists

func ThreadExists(tx *gorm.DB, nodeID, id base.ID) bool

Types

type Node

type Node struct {
	ID       base.ID `gorm:"type:bigint;primaryKey;not null"`
	ParentID null.ID `gorm:"type:bigint;not null;default:0"`

	// An unique name for this node, or empty.
	Name null.String `gorm:"unique;default:null"`

	// The display name for this node
	Title string `gorm:"not null"`

	// If the node is created by a user, this field will be filled.
	UserID null.ID `gorm:"type:bigint;not null;default:0"`

	ThreadsCount int64 `gorm:"not null;default:0"`

	AvatarURL   string `gorm:"not null"`
	Description string `gorm:"not null"`

	CreatedAt time.Time
	DeletedAt time.Time
}

A node (forum) contains many threads (posts), and could be nested.

func GetNodeByID

func GetNodeByID(tx *gorm.DB, id base.ID) *Node

func ListNodeChildren

func ListNodeChildren(tx *gorm.DB, parentID base.ID) (nodes []Node)

type Thread

type Thread struct {
	ID     base.ID `gorm:"type:bigint;primaryKey;not null"`
	NodeID base.ID `gorm:"type:bigint;not null;default:0"`

	// 0 means that it's a "root" thread.
	ReplyForID   null.ID `gorm:"type:bigint;not null;default:0"`
	RepliesCount int64   `gorm:"type:bigint;not null;default:0"`

	UserID base.ID `gorm:"type:bigint;not null;default:0"`

	// An unique name for this thread, or empty.
	Name null.String `gorm:"unique;default:null"`

	Title    string `gorm:"not null"`
	Content  string `gorm:"not null"`
	Abstract string `gorm:"not null"`

	// auto populated from content
	ImagesURL string `gorm:"not null"`

	CreatedAt time.Time `gorm:"not null"`
	UpdatedAt time.Time `gorm:"not null"`
	DeletedAt *time.Time
}

A thread(post) belongs to a special node, contains user-generated content, and can be nested ( reply ).

func GetThreadByID

func GetThreadByID(tx *gorm.DB, nodeID, id base.ID) *Thread

func ListThreads

func ListThreads(tx *gorm.DB, nodeID, replyForID base.ID, updatedBefore null.Time, limit int) (threads []Thread)

func (*Thread) BeforeCreate

func (m *Thread) BeforeCreate(tx *gorm.DB) (err error)

func (*Thread) BeforeSave

func (m *Thread) BeforeSave(tx *gorm.DB) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL