Files
leanote/app/info/NotebookInfo.go

62 lines
1.9 KiB
Go
Raw Normal View History

2014-05-07 13:06:24 +08:00
package info
import (
"gopkg.in/mgo.v2/bson"
2014-05-07 13:06:24 +08:00
"time"
)
// 在数据库中每个
// 修改字段必须要在NotebookService中修改ParseAndSortNotebooks(没有匿名字段), 以后重构
type Notebook struct {
NotebookId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
UserId bson.ObjectId `bson:"UserId"`
ParentNotebookId bson.ObjectId `bson:"ParentNotebookId,omitempty"` // 上级
Seq int `Seq` // 排序
Title string `Title` // 标题
2014-11-12 17:32:03 +08:00
UrlTitle string `UrlTitle` // Url标题 2014/11.11加
2014-05-07 13:06:24 +08:00
NumberNotes int `NumberNotes` // 笔记数
IsTrash bool `IsTrash,omitempty` // 是否是trash, 默认是false
IsBlog bool `IsBlog,omitempty` // 是否是Blog 2013/12/29 新加
CreatedTime time.Time `CreatedTime,omitempty`
UpdatedTime time.Time `UpdatedTime,omitempty`
2015-11-13 17:58:41 +08:00
2015-03-31 14:27:26 +08:00
// 2015/1/15, 更新序号
2015-11-13 17:58:41 +08:00
Usn int `Usn` // UpdateSequenceNum
2015-03-31 14:27:26 +08:00
IsDeleted bool `IsDeleted`
2014-05-07 13:06:24 +08:00
}
// 仅仅是为了返回前台
2014-09-10 22:44:43 +08:00
type SubNotebooks []*Notebooks // 存地址, 为了生成tree
2014-05-07 13:06:24 +08:00
type Notebooks struct {
Notebook
Subs SubNotebooks // 子notebook 在数据库中是没有的
}
// SubNotebook sort
func (this SubNotebooks) Len() int {
return len(this)
}
func (this SubNotebooks) Less(i, j int) bool {
2014-09-10 22:44:43 +08:00
return (*this[i]).Seq < (*this[j]).Seq
2014-05-07 13:06:24 +08:00
}
func (this SubNotebooks) Swap(i, j int) {
this[i], this[j] = this[j], this[i]
}
/*
修改方案, 因为要共享notebook的问题, 所以还是每个notebook一条记录
{
notebookId,
title,
seq,
parentNoteBookId, // 上级
userId
}
得到所有该用户的notebook, 然后组装成tree返回之
更新顺序
添加notebook
更新notebook
删除notebook
*/