models

package
v0.0.0-...-1abd83c Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RankNoPoint = -1
	RankNormal  = 0
	RankAwesome = 1
)

Variables

View Source
var (
	ADMIN_LOGINS = []string{"admin"}
)
View Source
var Cache cache.Cache
View Source
var (
	PushCenter *pubsub.PubSub
)

Functions

func CreateNode

func CreateNode(n *Node) (err error)

func CreateReply

func CreateReply(r *Reply) (err error)

func CreateTopic

func CreateTopic(t *Topic) error

func DeleteNode

func DeleteNode(n *Node) (err error)

func FindTopicPages

func FindTopicPages(channel string, nodeId, page, perPage int) (topics []*Topic, pageInfo Pagination)

func GenerateAvatar

func GenerateAvatar(name string) error

func GetRand

func GetRand() int

func GetReplyCount

func GetReplyCount() int

func GetSearchPages

func GetSearchPages(search string, page int, perPage int) (topics []*Topic, pageInfo Pagination)

func GetSetting

func GetSetting(key string) (out string)

func GetTopicCount

func GetTopicCount() (count int)

func GetUserCount

func GetUserCount() int

func Init

func Init()

func InitNodeGroup

func InitNodeGroup()

先初始化两个节点组

func InsertSetting

func InsertSetting(s Setting) error

func NotifyMention

func NotifyMention(userId, actorId int32, notifyableType string, notifyableId int32) error

func PushMessage

func PushMessage(channel string, message interface{})

func PushNotifyInfoToUser

func PushNotifyInfoToUser(userId int32, note Notification, isNew bool)

func RepliesCountCached

func RepliesCountCached() (count int)

func Subscribe

func Subscribe(channel string, callback func(message interface{}))

func TableName

func TableName(name string) string

func TopicsCountCached

func TopicsCountCached() (count int)

func UpdateNode

func UpdateNode(n *Node) (err error)

func UpdateReply

func UpdateReply(reply Reply) error

func UpdateSetting

func UpdateSetting(setting Setting) error

func UpdateTopic

func UpdateTopic(t *Topic) validation.Validation

func UsersCountCached

func UsersCountCached() (count int)

Types

type BaseModel

type BaseModel struct {
	Id        int32
	DeletedAt *time.Time
}

func (BaseModel) IsDeleted

func (m BaseModel) IsDeleted() bool

func (BaseModel) NewRecord

func (m BaseModel) NewRecord() bool

type Followable

type Followable struct {
	Id         int32     `orm:"pk;auto"`
	FollowType string    `orm:"size(20)"`
	TopicId    int32     ``
	Topic      *Topic    `orm:"-"`
	UserId     int32     ``
	User       *User     `orm:"-"`
	CreatedAt  time.Time `orm:"type(datetime);auto_now_add"`
	UpdatedAt  time.Time `orm:"type(datetime);auto_now"`
}

func (*Followable) TableName

func (f *Followable) TableName() string

type Node

type Node struct {
	Id        int32      `orm:"pk;auto"`
	Name      string     `orm:"unique"`
	Summary   string     `orm:"type(text)"`
	NodeGroup *NodeGroup `orm:"rel(fk)"`
	Sort      int        `orm:"default(0)"`
	CreatedAt time.Time  `orm:"type(datetime);auto_now_add"`
	UpdatedAt time.Time  `orm:"type(datetime);auto_now"`
	DeletedAt time.Time  `orm:"type(datetime);null"`
}

NodeGroupId int “

func FindAllNodes

func FindAllNodes() (nodes []*Node)

func FindNodeBySort

func FindNodeBySort(limit int) (nodes []*Node)

func GetNodeById

func GetNodeById(id int32) (node Node, err error)

func (*Node) NewRecord

func (n *Node) NewRecord() bool

func (*Node) TableName

func (n *Node) TableName() string

type NodeGroup

type NodeGroup struct {
	Id    int32   `orm:"pk;auto"`
	Name  string  `orm:"unique"`
	Sort  int     `orm:"default(0)"`
	Nodes []*Node `orm:"reverse(many)"`
}

func FindAllNodeGroups

func FindAllNodeGroups() (groups []NodeGroup)

这一步需要优化

func (*NodeGroup) TableName

func (n *NodeGroup) TableName() string

type Notification

type Notification struct {
	Id             int32     ``
	NotifyType     string    ``
	Read           bool      `orm:"default(false)"`
	User           *User     `orm:"rel(fk)"`
	Actor          *User     `orm:"rel(fk)"`
	NotifyableType string    ``
	NotifyableId   int32     ``
	CreatedAt      time.Time `orm:"auto_now_add;type(datetime)"`
	UpdatedAt      time.Time `orm:"auto_now;type(datetime)"`
}

func (*Notification) IsMention

func (n *Notification) IsMention() bool

func (*Notification) IsNotifyableReply

func (n *Notification) IsNotifyableReply() bool

func (*Notification) IsNotifyableTopic

func (n *Notification) IsNotifyableTopic() bool

func (*Notification) IsReply

func (n *Notification) IsReply() bool

func (*Notification) IsTopic

func (n *Notification) IsTopic() bool

func (*Notification) NotifyableTitle

func (n *Notification) NotifyableTitle() string

func (*Notification) NotifyableURL

func (n *Notification) NotifyableURL() string

func (*Notification) Reply

func (n *Notification) Reply() (r Reply, err error)

func (*Notification) TableName

func (n *Notification) TableName() string

func (*Notification) Topic

func (n *Notification) Topic() (t Topic)

type NotifyInfo

type NotifyInfo struct {
	UnreadCount int32  `json:"unread_count"`
	IsNew       bool   `json:"is_new"`
	Title       string `json:"title"`
	Avatar      string `json:"avatar"`
	Path        string `json:"path"`
}

type Pagination

type Pagination struct {
	Query        orm.QuerySeter
	TotalEntites int
	PerPage      int
	Path         string
	Page         int
	TotalPages   int
}

func (*Pagination) Paginate

func (p *Pagination) Paginate(page int) orm.QuerySeter

type Reply

type Reply struct {
	Id        int32     `orm:"pk;auto"`
	User      *User     `orm:"rel(fk)"`
	Topic     *Topic    `orm:"rel(fk)"`
	Body      string    `orm:"type:text;"`
	IsDeleted bool      ``
	CreatedAt time.Time `orm:"auto_now_add;type(datetime)"`
	UpdatedAt time.Time `orm:"type(datetime);auto_now"`
}

func GetReplyById

func GetReplyById(id int32) (reply Reply, err error)

func GetReplyByTopicId

func GetReplyByTopicId(id int32) (reply []Reply, err error)

获取文章的所有评论

func (*Reply) AfterCreate

func (r *Reply) AfterCreate() (err error)

func (*Reply) BeforeCreate

func (r *Reply) BeforeCreate() (err error)

func (*Reply) BeforeDelete

func (r *Reply) BeforeDelete() (err error)

func (*Reply) CheckMention

func (r *Reply) CheckMention()

func (*Reply) Del

func (r *Reply) Del() (err error)

func (*Reply) NewRecord

func (r *Reply) NewRecord() bool

func (*Reply) NotifyReply

func (r *Reply) NotifyReply() error

func (*Reply) TableName

func (r *Reply) TableName() string

type Setting

type Setting struct {
	Id  int32  `orm:"pk;auto"`
	Key string ``
	Val string ``
}

func FindSettingByKey

func FindSettingByKey(key string) (s Setting)

func GetSettings

func GetSettings() ([]*Setting, error)

func (*Setting) AfterSave

func (s *Setting) AfterSave()

func (*Setting) RewriteCache

func (s *Setting) RewriteCache()

func (*Setting) TableName

func (s *Setting) TableName() string

type Topic

type Topic struct {
	Id                 int32     `orm:"pk;auto"`
	User               *User     `orm:"rel(fk)"`
	Node               *Node     `orm:"rel(fk)"`
	Title              string    ``
	Body               string    `orm:"type(text)"`
	Replies            []*Reply  `orm:"reverse(many)"`
	RepliesCount       int32     `orm:"default(0)"`
	LastActiveMark     int64     `orm:"default(0)"`
	LastRepliedAt      time.Time `orm:"type(datetime);null"`
	LastReplyId        int32     ``
	LastReplyUser      *User     `orm:"-"`
	LastReplyUserLogin string    ``
	StarsCount         int32     `orm:"default(0)"`
	WatchesCount       int32     `orm:"default(0)"`
	Rank               int32     `orm:"default(0)"`
	CreatedAt          time.Time `orm:"type(datetime);auto_now_add"`
	UpdatedAt          time.Time `orm:"type(datetime);auto_now"`
	DeletedAt          time.Time `orm:"type(datetime);null"`
}

func GetRecentTopics

func GetRecentTopics(user_id int32) (topic []Topic, err error)

获取最近的10篇文章

func GetTopicById

func GetTopicById(id int32) (topic Topic, err error)

func GetTopicByUserId

func GetTopicByUserId(user_id int32) (topic []Topic, err error)

func (*Topic) CheckMention

func (t *Topic) CheckMention()

func (*Topic) DeleteTopic

func (t *Topic) DeleteTopic() error

func (*Topic) FollowerIds

func (t *Topic) FollowerIds() (ids []int32)

func (Topic) IsAwesome

func (t Topic) IsAwesome() bool

func (Topic) IsNoPoint

func (t Topic) IsNoPoint() bool

func (Topic) IsNormal

func (t Topic) IsNormal() bool

func (*Topic) NewRecord

func (t *Topic) NewRecord() bool

func (*Topic) TableName

func (t *Topic) TableName() string

func (Topic) URL

func (t Topic) URL() string

func (*Topic) UpdateLastReply

func (t *Topic) UpdateLastReply(reply *Reply) (err error)

func (*Topic) UpdateRank

func (t *Topic) UpdateRank(rank int) error

type User

type User struct {
	Id          int32     `orm:"pk;auto"`
	Login       string    `orm:"size(100)" valid:"Required;MaxSize(100)"`
	Password    string    `orm:"size(100)" valid:"Required;MaxSize(100)"`
	Email       string    `orm:"size(100)" valid:"Email;MaxSize(100)"`
	Avatar      string    `orm:"size(100)"`
	GitHub      string    `orm:"size(100)"`
	Twitter     string    `orm:"size(100)"`
	HomePage    string    `orm:"size(100)"`
	Tagline     string    `orm:"size(100)"`
	Description string    `orm:"size(250)"`
	Location    string    `orm:"size(200)"`
	Topics      []*Topic  `orm:"-"`
	Replies     []*Reply  `orm:"-"`
	CreatedAt   time.Time `orm:"type(datetime);auto_now_add"`
	UpdatedAt   time.Time `orm:"type(datetime);auto_now"`
	DeletedAt   time.Time `orm:"type(datetime);null"`
}

func FindUserByLogin

func FindUserByLogin(login string) (u *User, err error)

func GetUserById

func GetUserById(id int) (u *User, err error)

func UpdateUserProfile

func UpdateUserProfile(u *User) (user User, err error)

func (User) BeforeCreate

func (u User) BeforeCreate() error

func (*User) ClearNotifications

func (u *User) ClearNotifications() error

func (User) EncodePassword

func (u User) EncodePassword(raw string) (md5Digest string)

func (User) GavatarURL

func (u User) GavatarURL(size string) string

生成图片路径

func (User) IsAdmin

func (u User) IsAdmin() bool

func (User) IsStared

func (u User) IsStared(t Topic) bool

func (User) IsWatched

func (u User) IsWatched(t Topic) bool

func (*User) NewRecord

func (u *User) NewRecord() bool

func (*User) NotificationsPage

func (u *User) NotificationsPage(page, perPage int) (notes []Notification, pageInfo Pagination)

func (User) NotifyChannelId

func (u User) NotifyChannelId() string

func (*User) ReadNotifications

func (u *User) ReadNotifications(notes []Notification) error

func (User) SameAs

func (u User) SameAs(obj interface{}) bool

func (User) Signin

func (u User) Signin(login string, password string) (user User, v validation.Validation)

func (User) Signup

func (u User) Signup(login string, email string, password string, passwordConfirm string) (user User, err error)

func (User) Star

func (u User) Star(t Topic) bool

func (*User) TableName

func (u *User) TableName() string

func (User) UnReadNotificationsCount

func (u User) UnReadNotificationsCount() (count int32)

func (User) UnStar

func (u User) UnStar(t Topic) bool

func (User) UnWatch

func (u User) UnWatch(t Topic) bool

func (User) UpdatePassword

func (u User) UpdatePassword(oldPassword, newPassword, confirmPassword string) error

func (User) Watch

func (u User) Watch(t Topic) bool

Jump to

Keyboard shortcuts

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