Documentation ¶
Index ¶
- Constants
- type Category
- func CreateCategory(ctx context.Context, name, alias, description string, position int64) (*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 int64) (*Category, error)
- type Comment
- type GithubUser
- type Session
- type Statistic
- 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 ReadUsersByIds(ctx context.Context, ids []string) ([]*User, 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 (u *User) Name() string
- 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 (u *User) Role() string
- func (user *User) UpdateComment(ctx context.Context, id, body string) (*Comment, error)
- func (u *User) UpdateProfile(ctx context.Context, nickname, biography string) error
- func (user *User) UpdateTopic(ctx context.Context, id, title, body, categoryID string) (*Topic, error)
Constants ¶
const (
LIMIT = 50
)
Topic related CONST
const SolidStatisticID = "540cbd3c-f4eb-479c-bcd8-b5629af57267"
SolidStatisticID is used to generate a solid id from name
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Category ¶
type Category struct { CategoryID string Name string Alias string Description string TopicsCount int64 LastTopicID sql.NullString Position int64 CreatedAt time.Time UpdatedAt time.Time }
Category is used to categorize topics.
func CreateCategory ¶
func CreateCategory(ctx context.Context, name, alias, description string, position int64) (*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).
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
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 Statistic ¶ added in v0.10.0
type Statistic struct { StatisticID string `sql:"statistic_id,pk"` Name string `sql:"name,notnull"` Count int64 `sql:"count,notnull"` CreatedAt time.Time `sql:"created_at"` UpdatedAt time.Time `sql:"updated_at"` }
Statistic is the body of statistic
type Topic ¶
type Topic struct { TopicID string Title string Body string CommentsCount int64 CategoryID string UserID string Score int CreatedAt time.Time UpdatedAt time.Time User *User Category *Category }
Topic is what use talking about
func ReadTopics ¶
ReadTopics read all topics, parameters: offset default time.Now()
type User ¶
type User struct { UserID string Email sql.NullString Username string Nickname string Biography string EncryptedPassword sql.NullString GithubID sql.NullString CreatedAt time.Time UpdatedAt time.Time SessionID string // 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 ReadUsersByIds ¶ added in v0.10.0
ReadUsersByIds by users' id
func (*User) CreateComment ¶
CreateComment create a new comment
func (*User) CreateTopic ¶
CreateTopic create a new Topic
func (*User) DeleteComment ¶
DeleteComment delete a comment by ID
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