models

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2020 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddComment

func AddComment(c *Comment) (err error)

AddComment adds a new Comment to the database.

func AddCourse

func AddCourse(c *Course) (err error)

AddCourse adds a new Course to the database.

func AddPost

func AddPost(p *Post) (err error)

AddPost adds a new Post to the database.

func AddUser

func AddUser(u *User) (err error)

AddUser adds a new User to the database.

func DeleteComment

func DeleteComment(id string) (err error)

DeleteComment deletes a comment from the database.

func DeletePost

func DeletePost(id string) (err error)

DeletePost deletes a post from the database.

func GetUserPostCount

func GetUserPostCount(user string) (i int64, err error)

GetUserPostCount returns number of posts by a specific user.

func HasUser

func HasUser(user string) (has bool)

HasUser returns whether a user exists in the database.

func SetupEngine

func SetupEngine() *xorm.Engine

SetupEngine sets up an XORM engine according to the database configuration and syncs the schema.

func UnvotePost

func UnvotePost(user string, post int64) (err error)

func UpdateComment

func UpdateComment(c *Comment) (err error)

UpdateComment updates a comment in the database.

func UpdatePost

func UpdatePost(p *Post) (err error)

UpdatePost updates a post in the database.

func UpdateUser

func UpdateUser(u *User) (err error)

UpdateUser updates a user in the database.

func UpdateUserAdmin

func UpdateUserAdmin(u *User) (err error)

UpdateUserAdmin updates a user in the database including the IsAdmin field.

func UpdateUserBadge

func UpdateUserBadge(u *User) (err error)

UpdateUserBadge updates a user in the database including the Badge field, even if the field is empty.

func UpvotePost

func UpvotePost(user string, post int64) (err error)

Types

type Comment

type Comment struct {
	CommentID     int64         `xorm:"pk autoincr"`
	PostID        int64         `xorm:"notnull"`
	PosterID      string        `xorm:"notnull"`
	Poster        *User         `xorm:"-"`
	Text          string        `xorm:"notnull"`
	FormattedText template.HTML `xorm:"-"`
	CreatedUnix   int64         `xorm:"created"`
	Created       string        `xorm:"-"`
	UpdatedUnix   int64         `xorm:"updated"`
}

Comment represents a comment on a Post. It keeps track of the poster and which post it is posted to.

func GetComment

func GetComment(id string) (*Comment, error)

GetComment gets a comment based on the ID. It will return the pointer to the Comment, and whether there was an error.

func (*Comment) LoadCreated

func (c *Comment) LoadCreated() (err error)

LoadCreated loads the created time of a comment in a non-mapped field relative to the current time.

func (*Comment) LoadPoster

func (c *Comment) LoadPoster() (err error)

LoadPoster loads the poster of a comment in the non-mapped field of the Comment struct.

type Course

type Course struct {
	Code        string `xorm:"pk varchar(64)"`
	Name        string `xorm:"notnull text"`
	Visible     bool   `xorm:"notnull"`
	Locked      bool   `xorm:"notnull"`
	PostsCount  int64  `xorm:"-"`
	Posts       []Post `xorm:"-"`
	CreatedUnix int64  `xorm:"created"`
	Created     string `xorm:"-"`
	UpdatedUnix int64  `xorm:"updated"`
}

Course represents a sub-forum on a website, and is defined with a course code and a name. It keeps track of number of posts, whether that forum is locked, visible, and so on.

func GetCourse

func GetCourse(code string) (*Course, error)

GetCourse gets a Course based on a course code. It will return a pointer to the Course struct, and whether there was an error or not.

func GetCourses

func GetCourses() (courses []Course)

GetCourses returns a list of all courses in the database.

func (*Course) LoadPosts

func (c *Course) LoadPosts() (err error)

LoadPosts will load all the posts of the course into a non-mapped field.

func (*Course) LoadPostsCount

func (c *Course) LoadPostsCount() (err error)

LoadPostsCount loads the posts count of a course in a non-mapped field.

type HotPosts

type HotPosts []Post

HotPosts implements sort.Interface for []Post based on iota score diminished by time.

func (HotPosts) Len

func (p HotPosts) Len() int

func (HotPosts) Less

func (p HotPosts) Less(i, j int) bool

func (HotPosts) Swap

func (p HotPosts) Swap(i, j int)

type NewPosts

type NewPosts []Post

NewPosts implements sort.Interface for []Post based on new posts.

func (NewPosts) Len

func (p NewPosts) Len() int

func (NewPosts) Less

func (p NewPosts) Less(i, j int) bool

func (NewPosts) Swap

func (p NewPosts) Swap(i, j int)

type Post

type Post struct {
	PostID        int64     `xorm:"pk autoincr"`
	CourseCode    string    `xorm:"text notnull"`
	PosterID      string    `xorm:"notnull"`
	Poster        *User     `xorm:"-"`
	Locked        bool      `xorm:"notnull"` // Whether the comments are locked.
	Comments      []Comment `xorm:"-"`
	CommentsCount int64     `xorm:"-"`
	Title         string    `xorm:"text notnull"`
	Text          string    `xorm:"text notnull"`
	CreatedUnix   int64     `xorm:"created"`
	Created       string    `xorm:"-"`
	UpdatedUnix   int64     `xorm:"updated"`
	Anonymous     bool      `xorm:"notnull"`
	AnonName      string    `xorm:"text null"`
	Iota          int64
}

Post represents a post in one of the Courses by one of the Users. It keeps track of the poster, course, comments (and comment count), whether it is an anonymous post, and so on.

func GetAllUserPosts

func GetAllUserPosts(user string) (p []Post, err error)

GetAllUserPosts returns all of the post created by a specific user.

func GetPost

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

GetPost gets a Post based on the ID. It will return the pointer to the Post, and whether there was an error.

func (*Post) LoadComments

func (p *Post) LoadComments() (err error)

LoadComments loads the comments of the post into a non-mapped field.

type TopPosts

type TopPosts []Post

TopPosts implements sort.Interface for []Post based on highest iota.

func (TopPosts) Len

func (p TopPosts) Len() int

func (TopPosts) Less

func (p TopPosts) Less(i, j int) bool

func (TopPosts) Swap

func (p TopPosts) Swap(i, j int)

type User

type User struct {
	Username      string `xorm:"pk"`
	FullName      string `xorm:"text null"`
	Badge         string `xorm:"text null"`
	IsAdmin       bool   `xorm:"bool"`
	Iota          int64
	Created       string  `xorm:"-"`
	CreatedUnix   int64   `xorm:"created"`
	Upvoted       []int64 // Post IDs which the user upvoted.
	Suspended     bool    `xorm:"notnull"`
	SuspendReason string  `xorm:"text null"`
}

User represents a website user. It keeps track of the iota, settings (such as badges), and whether they have administrative privileges.

func GetUser

func GetUser(user string) (*User, error)

GetUser gets a user based on their username.

Jump to

Keyboard shortcuts

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