core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ActionUsage          = "usage"           // 帮助
	ActionSwitchEnglish  = "en"              // 切换到英文
	ActionSwitchChinese  = "zh"              // 切换到中文
	ActionRandomCourse   = "random"          // 随机课程
	ActionShowCourse     = "show_course"     // 开始课程
	ActionShowQuestion   = "show_question"   // 开始答题
	ActionAnswerQuestion = "answer_question" // 答题
)
View Source
const (
	CommandSourcePlainText = "plain_text"
	CommandSourceSnapshot  = "snapshot"
	CommandSourceAPI       = "api" // api
)
View Source
const (
	TaskStatePending   = "PENDING"   // 任务初始化
	TaskStateCourse    = "COURSE"    // 正在学习
	TaskStateQuestion  = "QUESTION"  // 正在答题
	TaskStateCancelled = "CANCELLED" // 任务已取消
	TaskStateFinish    = "FINISH"    // 课程结束,顺利毕业
)

Variables

This section is empty.

Functions

func AnswerToString

func AnswerToString(answer int) string

func ValidateCourse

func ValidateCourse(course *Course) error

Types

type Command

type Command struct {
	ID        int64      `gorm:"PRIMARY_KEY" json:"id,omitempty"`
	CreatedAt time.Time  `json:"created_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	TraceID   string     `gorm:"size:36" json:"trace_id,omitempty"`
	UserID    string     `gorm:"size:36" json:"user_id,omitempty"`
	Action    string     `gorm:"size:256" json:"action,omitempty"`
	Answer    int        `json:"answer,omitempty"`
	Source    string     `json:"source,omitempty"`
}

type CommandParser

type CommandParser interface {
	Parse(ctx context.Context, input string) ([]*Command, error)
	Encode(ctx context.Context, cmds ...*Command) string
}

type CommandStore

type CommandStore interface {
	Create(ctx context.Context, command *Command) error
	Delete(ctx context.Context, command *Command) error
	Deletes(ctx context.Context, commands []*Command) error
	ListPending(ctx context.Context, limit int) ([]*Command, error)
}

type Course

type Course struct {
	ID        int64       `gorm:"PRIMARY_KEY" json:"id,omitempty"`
	Language  string      `gorm:"size:36" json:"language,omitempty" yaml:"language"`
	Title     string      `gorm:"size:128" json:"title,omitempty" yaml:"title"`
	Summary   string      `gorm:"size:1024" json:"summary,omitempty" yaml:"summary"`
	Content   string      `gorm:"type:LONGTEXT" json:"content,omitempty" yaml:"content"`
	URL       string      `gorm:"size:256" json:"url,omitempty" yaml:"url"`
	Questions []*Question `gorm:"-" json:"questions,omitempty" yaml:"questions"`
}

func (*Course) Question

func (lesson *Course) Question(idx int) (*Question, bool)

type CourseStore

type CourseStore interface {
	Add(ctx context.Context, course *Course) error
	ListAll(ctx context.Context) ([]*Course, error)
	ListLanguage(ctx context.Context, language string) ([]*Course, error)
	Find(ctx context.Context, id int64) (*Course, error)
	FindNext(ctx context.Context, course *Course) (*Course, error)
}

type Question

type Question struct {
	Content string   `json:"content,omitempty" yaml:"content"`
	Choices []string `json:"choices,omitempty" yaml:"choices"`
	Answer  int      `json:"answer,omitempty" yaml:"answer"` // >= 0
}

type Task

type Task struct {
	ID         int64     `gorm:"PRIMARY_KEY" json:"id,omitempty"`
	CreatedAt  time.Time `json:"created_at,omitempty"`
	UpdatedAt  time.Time `json:"updated_at,omitempty"`
	Version    int64     `json:"version,omitempty"`
	Language   string    `gorm:"size:24" json:"language,omitempty"`
	UserID     string    `gorm:"size:36" json:"user_id,omitempty"`
	Creator    string    `gorm:"size:36" json:"creator,omitempty"`
	Info       string    `gorm:"size:512" json:"info,omitempty"`
	Course     int64     `json:"course,omitempty"`
	Question   int       `json:"question,omitempty"`
	State      string    `gorm:"size:36" json:"state,omitempty"`
	BlockUntil time.Time `json:"block_until,omitempty"`
}

func (*Task) IsActive

func (t *Task) IsActive() bool

func (*Task) IsBlocked

func (t *Task) IsBlocked() (blocked bool, remain time.Duration)

func (*Task) IsDone

func (t *Task) IsDone() bool

func (*Task) IsMandatory

func (t *Task) IsMandatory() bool

func (*Task) IsPending

func (t *Task) IsPending() bool

type TaskStore

type TaskStore interface {
	Create(ctx context.Context, task *Task) error
	Update(ctx context.Context, task *Task) error
	UpdateVersion(ctx context.Context, task *Task, version int64) error
	Find(ctx context.Context, id int64) (*Task, error)
	// FindUser return user's last task
	FindUser(ctx context.Context, userID string) (*Task, error)
}

type Transfer

type Transfer struct {
	TraceID    string `gorm:"size:36;PRIMARY_KEY" json:"trace_id,omitempty"`
	OpponentID string `gorm:"size:36" json:"opponent_id,omitempty"`
	AssetID    string `gorm:"size:36" json:"asset_id,omitempty"`
	Amount     string `gorm:"size:64" json:"amount,omitempty"`
	Memo       string `gorm:"size:256" json:"memo,omitempty"`
}

type User

type User struct {
	ID        int64     `gorm:"PRIMARY_KEY" json:"id,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	MixinID   string    `gorm:"size:36" json:"id,omitempty"`
	Language  string    `gorm:"size:36" json:"language,omitempty"`
}

type UserStore

type UserStore interface {
	Create(ctx context.Context, user *User) error
	Update(ctx context.Context, user *User) error
	FindMixinID(ctx context.Context, mixinID string) (*User, error)
}

type WalletService

type WalletService interface {
	Transfer(ctx context.Context, req *Transfer) error
}

type WalletStore

type WalletStore interface {
	CreateTransfer(ctx context.Context, transfer *Transfer) error
	DeleteTransfers(ctx context.Context, traceIDs []string) error
	ListTransfers(ctx context.Context, limit int) ([]*Transfer, error)
	CountTransfers(ctx context.Context) (int64, error)
}

Jump to

Keyboard shortcuts

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