models

package
v0.0.0-...-c0c6cc4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2014 License: GPL-3.0 Imports: 17 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDbSession

func GetDbSession() *gorp.DbMap

func GetPostCount

func GetPostCount() (int64, error)

Returns the number of posts (on every board/thread)

func GetStringSetting

func GetStringSetting(key string) (value string, err error)

func GetThread

func GetThread(parent_id, page_id int) (error, *Post, []*Post)

Returns a pointer to the OP and a slice of post pointers for the given page number in the thread.

func GetUserCount

func GetUserCount() (int64, error)

func SetStringSetting

func SetStringSetting(key, value string) (err error)

Types

type Board

type Board struct {
	Id          int64  `db:"id"`
	Title       string `db:"title"`
	Description string `db:"description"`
	Order       int    `db:"ordering"`
}

func GetBoard

func GetBoard(id int) (*Board, error)

func GetBoards

func GetBoards() ([]*Board, error)

func NewBoard

func NewBoard(title, desc string, order int) *Board

func UpdateBoard

func UpdateBoard(title, desc string, order int, id int64) *Board

func (*Board) Delete

func (board *Board) Delete()

Deletes a board and all of the posts it contains

func (*Board) GetLatestPost

func (board *Board) GetLatestPost() BoardLatest

func (*Board) GetPagesInBoard

func (board *Board) GetPagesInBoard() int

func (*Board) GetThreads

func (board *Board) GetThreads(page int, user *User) ([]*JoinThreadView, error)

type BoardLatest

type BoardLatest struct {
	Op     *Post
	Latest *Post
}

type JoinBoardView

type JoinBoardView struct {
	Board       *Board      `db:"-"`
	Id          int64       `db:"id"`
	Title       string      `db:"title"`
	Description string      `db:"description"`
	Order       int         `db:"ordering"`
	ViewedOn    pq.NullTime `db:"viewed_on"`
}

func GetBoardsUnread

func GetBoardsUnread(user *User) ([]*JoinBoardView, error)

type JoinThreadView

type JoinThreadView struct {
	Thread      *Post       `db:"-"`
	Id          int64       `db:"id"`
	BoardId     int64       `db:"board_id"`
	Author      *User       `db:"-"`
	AuthorId    int64       `db:"author_id"`
	Title       string      `db:"title"`
	CreatedOn   time.Time   `db:"created_on"`
	LatestReply time.Time   `db:"latest_reply"`
	Sticky      bool        `db:"sticky"`
	Locked      bool        `db:"locked"`
	ViewedOn    pq.NullTime `db:"viewed_on"`
}

type Post

type Post struct {
	Id          int64         `db:"id"`
	BoardId     int64         `db:"board_id"`
	ParentId    sql.NullInt64 `db:"parent_id"`
	Author      *User         `db:"-"`
	AuthorId    int64         `db:"author_id"`
	Title       string        `db:"title"`
	Content     string        `db:"content"`
	CreatedOn   time.Time     `db:"created_on"`
	LatestReply time.Time     `db:"latest_reply"`
	LastEdit    time.Time     `db:"last_edit"`
	Sticky      bool          `db:"sticky"`
	Locked      bool          `db:"locked"`
}

func GetPost

func GetPost(id int) (*Post, error)

func NewPost

func NewPost(author *User, board *Board, title, content string) *Post

Initializes a new struct, adds some data, and returns the pointer to it

func (*Post) DeleteAllChildren

func (post *Post) DeleteAllChildren() error

Used when deleting a thread. This deletes all posts who are children of the OP.

func (*Post) GetLatestPost

func (post *Post) GetLatestPost() *Post

This is used primarily for threads. It will find the latest post in a thread, allowing for things like "last post was 10 minutes ago.

func (post *Post) GetLink() string

Generate a link to a post

func (*Post) GetPageInThread

func (post *Post) GetPageInThread() int

This function tells us which page this particular post is in within a thread based on the current value of posts_per_page

func (*Post) GetPagesInThread

func (post *Post) GetPagesInThread() int

Returns the number of pages contained by a thread. This won't work on post structs that have ParentIds.

func (*Post) GetThreadId

func (post *Post) GetThreadId() int64

Get the thread id for a post

func (*Post) PostGet

func (post *Post) PostGet(s gorp.SqlExecutor) error

Post-SELECT hook for gorp which adds a pointer to the author to the Post's struct

func (*Post) Validate

func (post *Post) Validate() error

Ensures that a post is valid

type Setting

type Setting struct {
	Key   string `db:"key"`
	Value string `db:"value"`
}

type User

type User struct {
	Id            int64          `db:"id"`
	GroupId       int64          `db:"group_id"`
	CreatedOn     time.Time      `db:"created_on"`
	Username      string         `db:"username"`
	Password      string         `db:"password"`
	Avatar        string         `db:"avatar"`
	Signature     sql.NullString `db:"signature"`
	Salt          string         `db:"salt"`
	StylesheetUrl sql.NullString `db:"stylesheet_url"`
	UserTitle     string         `db:"user_title"`
	LastSeen      time.Time      `db:"last_seen"`
	HideOnline    bool           `db:"hide_online"`
	LastUnreadAll pq.NullTime    `db:"last_unread_all"`
}

func AuthenticateUser

func AuthenticateUser(username, password string) (error, *User)

func GetLatestUser

func GetLatestUser() (*User, error)

func GetOnlineUsers

func GetOnlineUsers() (users []*User)

func GetUser

func GetUser(id int) (*User, error)

func NewUser

func NewUser(username, password string) *User

func (*User) CanModerate

func (user *User) CanModerate() bool

func (*User) GetPostCount

func (user *User) GetPostCount() int64

func (*User) GetPosts

func (user *User) GetPosts(page int) []*Post

func (*User) IsAdmin

func (user *User) IsAdmin() bool

func (*User) SetPassword

func (user *User) SetPassword(password string)

Converts the given string into an appropriate hash, resets the salt, and sets the Password attribute. Does *not* commit to the database.

type View

type View struct {
	Id     string    `db:"id"`
	Post   *Post     `db:"-"`
	PostId int64     `db:"post_id"`
	User   *User     `db:"-"`
	UserId int64     `db:"user_id"`
	Time   time.Time `db:"time"`
}

func AddView

func AddView(user *User, post *Post) *View

Jump to

Keyboard shortcuts

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