model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Status int         `json:"status"`
	Data   interface{} `json:"data"`
}

Cache is a struct used for caching posts, threads, index or errors.

type DeleteData

type DeleteData struct {
	ID       uint64 `json:"id"`
	Password string `json:"password"`
}

DeleteData is a struct used for incoming DELETE requests or successful POST requests.

func (*DeleteData) Validate

func (data *DeleteData) Validate() error

Validate checks if all fields are valid.

type Post

type Post struct {
	ID           uint64     `json:"id" gorm:"primary_key;AUTO_INCREMENT"`
	Content      string     `json:"content" gorm:"not null;size:1000"`
	Password     string     `json:"password,omitempty" gorm:"not null;size:128"`
	Pic          *string    `json:"pic,omitempty" gorm:"size:512"`
	ParentThread *uint64    `json:"parent_thread,omitempty"`
	ReplyTo      *uint64    `json:"reply_to,omitempty"`
	CreatedAt    *time.Time `json:"created_at" gorm:"not null;default:CURRENT_TIMESTAMP"`
	UpdatedAt    *time.Time `json:"updated_at,omitempty" gorm:"not null;default:CURRENT_TIMESTAMP"`
	Sticky       bool       `json:"sticky,omitempty"`
	Closed       bool       `json:"closed,omitempty"`
	Sage         bool       `json:"sage,omitempty" gorm:"-"` // This field is not stored
}

Post is the main struct. It defines how posts will be stored and represented.

func (*Post) AllowsReplies

func (post *Post) AllowsReplies() bool

AllowsReplies checks if this post allows being replied.

func (*Post) BeforeCreate

func (post *Post) BeforeCreate(scope *gorm.Scope) error

BeforeCreate makes the delete code if it's empty.

func (*Post) IsAParentThread

func (post *Post) IsAParentThread() bool

IsAParentThread checks if this post starts a parent thread.

func (*Post) MakeRelationWith

func (post *Post) MakeRelationWith(reply *Post)

MakeRelationWith adds the parent thread ID to the post based on the reply.

func (*Post) RepliesToAnotherPost

func (post *Post) RepliesToAnotherPost() bool

RepliesToAnotherPost checks if this post replies to another post.

func (*Post) Sages

func (post *Post) Sages() bool

Sages checks if parent thread must not be bumped.

func (*Post) TableName

func (post *Post) TableName() string

TableName sets the table name for the model Post.

func (*Post) Validate

func (post *Post) Validate() error

Validate checks if all fields are valid.

type UpdateData

type UpdateData struct {
	ID       uint64 `json:"id"`
	Password string `json:"password"`
	Sticky   bool   `json:"sticky"`
	Closed   bool   `json:"closed"`
}

UpdateData is a struct used for incoming PUT requests.

func (*UpdateData) Validate

func (data *UpdateData) Validate() error

Validate checks if all fields are valid.

Jump to

Keyboard shortcuts

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