models

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LIMIT = 50
)

Topic related CONST

View Source
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

func ElevateCategory(ctx context.Context, id string) (*Category, error)

ElevateCategory update category's info, e.g.: LastTopicID, TopicsCount

func ReadCategories

func ReadCategories(ctx context.Context) ([]*Category, error)

ReadCategories read categories order by position

func ReadCategory

func ReadCategory(ctx context.Context, id string) (*Category, error)

ReadCategory read a category by ID (uuid).

func UpdateCategory

func UpdateCategory(ctx context.Context, id, name, alias, description string, position int64) (*Category, error)

UpdateCategory update a category's attributes

func (*Category) ReadTopics

func (category *Category) ReadTopics(ctx context.Context, offset time.Time) ([]*Topic, error)

ReadTopics read topics by CategoryID order by created_at DESC

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 ReadTopic

func ReadTopic(ctx context.Context, id string) (*Topic, error)

ReadTopic read a topic by ID

func ReadTopics

func ReadTopics(ctx context.Context, offset time.Time) ([]*Topic, error)

ReadTopics read all topics, parameters: offset default time.Now()

func (*Topic) ReadComments

func (topic *Topic) ReadComments(ctx context.Context, offset time.Time) ([]*Comment, error)

ReadComments read comments by topicID, parameters: offset

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

func AuthenticateUser(ctx context.Context, tokenString string) (*User, error)

AuthenticateUser read a user by tokenString. tokenString is a jwt token, more about jwt: https://github.com/dgrijalva/jwt-go

func CreateGithubUser

func CreateGithubUser(ctx context.Context, code, sessionSecret string) (*User, error)

CreateGithubUser create a github user.

func CreateSession

func CreateSession(ctx context.Context, identity, password, sessionSecret string) (*User, error)

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 ReadUser

func ReadUser(ctx context.Context, id string) (*User, error)

ReadUser read user by id.

func ReadUserByUsernameOrEmail

func ReadUserByUsernameOrEmail(ctx context.Context, identity string) (*User, error)

ReadUserByUsernameOrEmail read user by identity, which is an email or username.

func ReadUsers

func ReadUsers(ctx context.Context, offset time.Time) ([]*User, error)

ReadUsers read users by offset

func ReadUsersByIds added in v0.10.0

func ReadUsersByIds(ctx context.Context, ids []string) ([]*User, error)

ReadUsersByIds by users' id

func (*User) CreateComment

func (user *User) CreateComment(ctx context.Context, topicID, body string) (*Comment, error)

CreateComment create a new comment

func (*User) CreateTopic

func (user *User) CreateTopic(ctx context.Context, title, body, categoryID string) (*Topic, error)

CreateTopic create a new Topic

func (*User) DeleteComment

func (user *User) DeleteComment(ctx context.Context, id string) error

DeleteComment delete a comment by ID

func (*User) Name

func (u *User) Name() string

Name is nickname or username

func (*User) ReadComments

func (user *User) ReadComments(ctx context.Context, offset time.Time) ([]*Comment, error)

ReadComments read comments by userID, parameters: offset

func (*User) ReadTopics

func (user *User) ReadTopics(ctx context.Context, offset time.Time) ([]*Topic, error)

ReadTopics read user's topics, parameters: offset default time.Now()

func (*User) Role

func (u *User) Role() string

Role of an user, contains admin and member for now.

func (*User) UpdateComment

func (user *User) UpdateComment(ctx context.Context, id, body string) (*Comment, error)

UpdateComment update the comment by id

func (*User) UpdateProfile

func (u *User) UpdateProfile(ctx context.Context, nickname, biography string) error

UpdateProfile update user's profile

func (*User) UpdateTopic

func (user *User) UpdateTopic(ctx context.Context, id, title, body, categoryID string) (*Topic, error)

UpdateTopic update a Topic by ID

Jump to

Keyboard shortcuts

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