Documentation
¶
Index ¶
- func AddComment(c *Comment) (err error)
- func AddCourse(c *Course) (err error)
- func AddPost(p *Post) (err error)
- func AddUser(u *User) (err error)
- func DeleteComment(id string) (err error)
- func DeletePost(id string) (err error)
- func GetUserPostCount(user string) (i int64, err error)
- func HasUser(user string) (has bool)
- func SetupEngine() *xorm.Engine
- func UnvotePost(user string, post int64) (err error)
- func UpdateComment(c *Comment) (err error)
- func UpdatePost(p *Post) (err error)
- func UpdateUser(u *User) (err error)
- func UpdateUserAdmin(u *User) (err error)
- func UpdateUserBadge(u *User) (err error)
- func UpvotePost(user string, post int64) (err error)
- type Comment
- type Course
- type HotPosts
- type NewPosts
- type Post
- type TopPosts
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddComment ¶
AddComment adds a new Comment to the database.
func DeleteComment ¶
DeleteComment deletes a comment from the database.
func DeletePost ¶
DeletePost deletes a post from the database.
func GetUserPostCount ¶
GetUserPostCount returns number of posts by a specific user.
func SetupEngine ¶
SetupEngine sets up an XORM engine according to the database configuration and syncs the schema.
func UnvotePost ¶
func UpdateComment ¶
UpdateComment updates a comment in the database.
func UpdateUserAdmin ¶
UpdateUserAdmin updates a user in the database including the IsAdmin field.
func UpdateUserBadge ¶
UpdateUserBadge updates a user in the database including the Badge field, even if the field is empty.
func UpvotePost ¶
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 ¶
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 ¶
LoadCreated loads the created time of a comment in a non-mapped field relative to the current time.
func (*Comment) LoadPoster ¶
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 ¶
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) LoadPostsCount ¶
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.
type NewPosts ¶
type NewPosts []Post
NewPosts implements sort.Interface for []Post based on new posts.
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 ¶
GetAllUserPosts returns all of the post created by a specific user.
func GetPost ¶
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 ¶
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.
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.