Documentation
¶
Index ¶
- type Category
- func CreateCategory(ctx context.Context, name, alias, description string, position int) (*Category, error)
- func ElevateCategory(ctx context.Context, id string) (*Category, error)
- func ReadCategories(ctx context.Context) ([]*Category, error)
- func ReadCategory(ctx context.Context, id string) (*Category, error)
- func UpdateCategory(ctx context.Context, id, name, alias, description string, position int) (*Category, error)
- type Comment
- type GithubUser
- type Session
- type Topic
- type User
- func AuthenticateUser(ctx context.Context, tokenString string) (*User, error)
- func CreateGithubUser(ctx context.Context, code, sessionSecret string) (*User, error)
- func CreateSession(ctx context.Context, identity, password, sessionSecret string) (*User, error)
- func CreateUser(ctx context.Context, email, username, nickname, biography, password string, ...) (*User, error)
- func ReadUser(ctx context.Context, id string) (*User, error)
- func ReadUserByUsernameOrEmail(ctx context.Context, identity string) (*User, error)
- func ReadUsers(ctx context.Context, offset time.Time) ([]*User, error)
- func (user *User) BeforeInsert(db orm.DB) error
- func (user *User) BeforeUpdate(db orm.DB) error
- func (user *User) CreateComment(ctx context.Context, topicID, body string) (*Comment, error)
- func (user *User) CreateTopic(ctx context.Context, title, body, categoryID string) (*Topic, error)
- func (user *User) DeleteComment(ctx context.Context, id string) error
- func (user *User) Name() string
- func (user *User) ReadComment(ctx context.Context, id string) (*Comment, error)
- func (user *User) ReadComments(ctx context.Context, offset time.Time) ([]*Comment, error)
- func (user *User) ReadTopics(ctx context.Context, offset time.Time) ([]*Topic, error)
- func (user *User) Role() string
- func (user *User) UpdateComment(ctx context.Context, id, body string) (*Comment, error)
- func (user *User) UpdateProfile(ctx context.Context, nickname, biography string) error
- func (user *User) UpdateTopic(ctx context.Context, id, title, body, categoryID string) (*Topic, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct {
CategoryID string `sql:"category_id,pk"`
Name string `sql:"name,notnull"`
Alias string `sql:"alias,notnull"`
Description string `sql:"description,notnull"`
TopicsCount int `sql:"topics_count,notnull"`
LastTopicID sql.NullString `sql:"last_topic_id"`
Position int `sql:"position,notnull"`
CreatedAt time.Time `sql:"created_at"`
UpdatedAt time.Time `sql:"updated_at"`
}
Category is used to categorize topics.
func CreateCategory ¶
func CreateCategory(ctx context.Context, name, alias, description string, position int) (*Category, error)
CreateCategory create a new category.
func ElevateCategory ¶
ElevateCategory update category's info, e.g.: LastTopicID, TopicsCount
func ReadCategories ¶
ReadCategories read categories order by position
func ReadCategory ¶
ReadCategory read a category by ID (uuid).
func UpdateCategory ¶
func UpdateCategory(ctx context.Context, id, name, alias, description string, position int) (*Category, error)
UpdateCategory update a category's attributes
func (*Category) BeforeInsert ¶
BeforeInsert hook insert
func (*Category) BeforeUpdate ¶
BeforeUpdate hook update
type Comment ¶
type Comment struct {
CommentID string `sql:"comment_id,pk"`
Body string `sql:"body"`
TopicID string `sql:"topic_id"`
UserID string `sql:"user_id"`
Score int `sql:"score,notnull"`
CreatedAt time.Time `sql:"created_at"`
UpdatedAt time.Time `sql:"updated_at"`
User *User
}
Comment is struct for comment of topic
func (*Comment) BeforeInsert ¶
BeforeInsert hook insert
type GithubUser ¶
type GithubUser struct {
Login string `json:"login"`
NodeID string `json:"node_id"`
Name string `json:"name"`
Email string `json:"email"`
}
GithubUser is the response body of github oauth.
type Session ¶
type Session struct {
SessionID string `sql:"session_id,pk"`
UserID string `sql:"user_id"`
Secret string `sql:"secret"`
CreatedAt time.Time `sql:"created_at"`
}
Session contains user's current login infomation
type Topic ¶
type Topic struct {
TopicID string `sql:"topic_id,pk"`
Title string `sql:"title,notnull"`
Body string `sql:"body,notnull"`
CommentsCount int `sql:"comments_count,notnull"`
CategoryID string `sql:"category_id,notnull"`
UserID string `sql:"user_id,notnull"`
Score int `sql:"score,notnull"`
CreatedAt time.Time `sql:"created_at"`
UpdatedAt time.Time `sql:"updated_at"`
User *User `sql:"-"`
Category *Category `sql:"-"`
}
Topic is what use talking about
func ReadTopics ¶
ReadTopics read all topics, parameters: offset default time.Now()
type User ¶
type User struct {
UserID string `sql:"user_id,pk"`
Email sql.NullString `sql:"email"`
Username string `sql:"username,notnull"`
Nickname string `sql:"nickname,notnull"`
Biography string `sql:"biography,notnull"`
EncryptedPassword sql.NullString `sql:"encrypted_password"`
GithubID sql.NullString `sql:"github_id"`
CreatedAt time.Time `sql:"created_at"`
UpdatedAt time.Time `sql:"updated_at"`
SessionID string `sql:"-"`
// contains filtered or unexported fields
}
User contains info of a register user
func AuthenticateUser ¶
AuthenticateUser read a user by tokenString. tokenString is a jwt token, more about jwt: https://github.com/dgrijalva/jwt-go
func CreateGithubUser ¶
CreateGithubUser create a github user.
func CreateSession ¶
CreateSession create a new user session
func CreateUser ¶
func CreateUser(ctx context.Context, email, username, nickname, biography, password string, sessionSecret string) (*User, error)
CreateUser create a new user
func ReadUserByUsernameOrEmail ¶
ReadUserByUsernameOrEmail read user by identity, which is an email or username.
func (*User) BeforeInsert ¶
BeforeInsert hook insert
func (*User) BeforeUpdate ¶
BeforeUpdate hook update
func (*User) CreateComment ¶
CreateComment create a new comment
func (*User) CreateTopic ¶
CreateTopic create a new Topic
func (*User) ReadComment ¶
func (*User) ReadComments ¶
ReadComments read comments by userID, parameters: offset
func (*User) ReadTopics ¶
ReadTopics read user's topics, parameters: offset default time.Now()
func (*User) UpdateComment ¶
UpdateComment update the comment by id
func (*User) UpdateProfile ¶
UpdateProfile update user's profile