models

package
v0.3.3 Latest Latest
Warning

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

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

Documentation

Overview

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

Neat Note. A notes sharing platform for university students. Copyright (C) 2020 Humaid AlQassimi

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

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, including comments.

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 UpdateUserCols added in v0.3.1

func UpdateUserCols(u *User, cols ...string) error

UpdatUserCols updates a user in the database including the specified columns, even if the fields are 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:"-" json:"-"`
	Text          string        `xorm:"notnull"`
	FormattedText template.HTML `xorm:"-" json:"-"`
	CreatedUnix   int64         `xorm:"created"`
	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 GetAllUserComments added in v0.3.1

func GetAllUserComments(user string) (c []Comment, err error)

GetAllUserComments returns all of the comments created by a specific user.

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) 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:"-" json:"-"`
	Posts       []Post `xorm:"-" json:"-"`
	CreatedUnix int64  `xorm:"created"`
	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:"-" json:"-"`
	Locked        bool      `xorm:"notnull"` // Whether the comments are locked.
	Comments      []Comment `xorm:"-" json:"-"`
	CommentsCount int64     `xorm:"-" json:"-"`
	Title         string    `xorm:"text notnull"`
	Text          string    `xorm:"text notnull"`
	CreatedUnix   int64     `xorm:"created"`
	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
	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.

func GetUsers added in v0.3.1

func GetUsers() (users []User)

GetUsers returns a list of all users in the database.

Jump to

Keyboard shortcuts

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