model

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 31, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired. ")
	TokenNotValidYet = errors.New("Token not active yet. ")
	TokenMalformed   = errors.New("That's not even a token. ")
	TokenInvalid     = errors.New("Couldn't handle this token. ")
)

Functions

func GetUserProblemType

func GetUserProblemType(userId uint) ([]string, error)

func Init

func Init(ctx context.Context) error

func PickRandonFinished

func PickRandonFinished(userId uint, ttype string) (bool, error)

PickRandonFinished 随机选一道做过的题

func PickRandonUnPicked

func PickRandonUnPicked(userId uint, ttype string) (bool, error)

PickRandonUnPicked 随机选一道没选过的题

Types

type Conf

type Conf struct {
	gorm.Model
	Name  string `gorm:"column:name"`
	Value string `gorm:"column:value"`
}

type CustomClaims

type CustomClaims struct {
	UserID uint   `json:"userId"`
	Name   string `json:"name"`
	Email  string `json:"email"`
	Phone  string `json:"phone"`
	Role   string `json:"role"`
	jwt.StandardClaims
}

载荷,可以加一些自己需要的信息

type JWT

type JWT struct {
	SigningKey []byte
}

JWT 签名结构

func NewJWT

func NewJWT() *JWT

NewJWT: 新建一个jwt实例

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

CreateToken 生成一个token

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)

ParseToken 解析Token

type LoginParam

type LoginParam struct {
	Name     string `json:"name" validate:"required"`
	Password string `json:"password" validate:"required"`
}

type OverviewRes added in v1.0.0

type OverviewRes struct {
	PersistDay   int        `json:"persist_day"`
	InterruptDay int        `json:"interrupt_day"`
	PersistNum   int        `json:"persist_num"`
	PersistTimes int        `json:"persist_times"`
	Todulist     []TodoItem `json:"todulist"`
}

type Problem

type Problem struct {
	gorm.Model
	Name      string `gorm:"column:name" json:"name" validate:"required"` //题目标题
	Content   string `gorm:"column:content;type:text" json:"content"`     //题解内容
	Result    string `gorm:"column:result;type:text" json:"result"`       //题目答案
	Link      string `gorm:"column:link" json:"link"`                     //题目链接
	Type      string `gorm:"column:type" json:"type"`                     //题目类别 algorithm、sql...
	SubType   string `gorm:"column:sub_type" json:"sub_type"`             //题目子类别 图、树、数组...
	IsPublic  bool   `gorm:"column:is_public" json:"is_public"`           //题目是否公开
	CreatorID uint   `gorm:"column:creator_id" json:"creator_id"`         //题目创建者ID
	Creator   User   `gorm:"foreignKey:CreatorID" json:"-"`               //题目创建者
}

func GetProblemByID

func GetProblemByID(id uint) (Problem, error)

GetProblemByID 获取指定ID的题目

func (Problem) AddToUserStudyPlan

func (p Problem) AddToUserStudyPlan(userId uint) error

将题目加入某用户的学习计划

type RegisterParam

type RegisterParam struct {
	Name     string `json:"name" validate:"required"`
	Email    string `json:"email"`
	Phone    string `json:"phone"`
	Password string `json:"password" validate:"required"`
}

type TodoItem added in v1.0.0

type TodoItem struct {
	Done    bool   `json:"done"`
	Content string `json:"content"`
}

type UpdateProblemParam

type UpdateProblemParam struct {
	ID       uint   `json:"id" validate:"required"`   //题目ID
	Name     string `json:"name" validate:"required"` //题目标题
	Content  string `json:"content"`                  //题解内容
	Result   string `json:"result"`                   //题目答案
	Link     string `json:"link"`                     //题目链接
	Type     string `json:"type"`                     //题目类别 algorithm、sql...
	SubType  string `json:"sub_type"`                 //题目子类别 图、树、数组...
	IsPublic bool   `json:"is_public"`                //题目是否公开
}

func (*UpdateProblemParam) ToMap

func (param *UpdateProblemParam) ToMap() map[string]interface{}

type User

type User struct {
	gorm.Model
	Name         string     `gorm:"column:name" json:"name"`
	Email        string     `gorm:"column:email" json:"email"`
	Phone        string     `gorm:"column:phone" json:"phone"`
	Password     string     `gorm:"column:password" json:"-"`
	Role         string     `gorm:"column:role" json:"role"`
	PersistDay   int        `gorm:"column:persist_day" json:"persist_day"`
	InterruptDay int        `gorm:"column:interrupt_day" json:"interrupt_day"`
	Config       UserConfig `gorm:"column:config;type:string" json:"config"`
}

func GetAllUsers

func GetAllUsers() ([]User, error)

func LoginCheck

func LoginCheck(param LoginParam) (User, error)

func Register

func Register(param RegisterParam) (User, error)

func (*User) UpdateComplete added in v1.0.0

func (u *User) UpdateComplete(complete bool) error

type UserConfig

type UserConfig struct {
	ProblemNum map[string]int `json:"problem_num"`
}

func (*UserConfig) Scan

func (uc *UserConfig) Scan(value interface{}) error

怎么从数据库取

func (UserConfig) Value

func (uc UserConfig) Value() (driver.Value, error)

怎么存在数据库中

type UserProblem

type UserProblem struct {
	gorm.Model
	UserId      uint      `gorm:"column:user_id;primaryKey"`    //用户ID
	ProblemId   uint      `gorm:"column:problem_id;primaryKey"` //题目ID
	ProblemType string    `gorm:"column:problem_type"`          //题目类型
	Picked      bool      `gorm:"column:picked"`                //是否被选
	PickTime    time.Time `gorm:"column:pick_time"`             //选题时间
	Finished    bool      `gorm:"column:finished"`              //是否完成
	Times       int       `gorm:"column:times"`                 //已做次数
}

func (UserProblem) RemoveFromUserPlan

func (up UserProblem) RemoveFromUserPlan() error

Jump to

Keyboard shortcuts

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