models

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

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

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 int) (*Category, error)

UpdateCategory update a category's attributes

func (*Category) BeforeInsert

func (c *Category) BeforeInsert(db orm.DB) error

BeforeInsert hook insert

func (*Category) BeforeUpdate

func (c *Category) BeforeUpdate(db orm.DB) error

BeforeUpdate hook update

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

func (*Comment) BeforeInsert

func (c *Comment) BeforeInsert(db orm.DB) error

BeforeInsert hook insert

func (*Comment) BeforeUpdate

func (c *Comment) BeforeUpdate(db orm.DB) error

BeforeUpdate hook update

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 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) BeforeInsert

func (t *Topic) BeforeInsert(db orm.DB) error

BeforeInsert hook insert

func (*Topic) BeforeUpdate

func (t *Topic) BeforeUpdate(db orm.DB) error

BeforeUpdate hook update

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         `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

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)

func (*User) BeforeInsert

func (user *User) BeforeInsert(db orm.DB) error

BeforeInsert hook insert

func (*User) BeforeUpdate

func (user *User) BeforeUpdate(db orm.DB) error

BeforeUpdate hook update

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

func (*User) Name

func (user *User) Name() string

Name is nickname or username

func (*User) ReadComment

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

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 (user *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 (user *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