leanote支持多用户, 所以每个表都会有userId字段.
笔记本
- 支持多级分类(无限级)
- 笔记本可共享
数据结构:
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` // 标题
IsTrash bool `IsTrash,omitempty` // 是否是trash, 默认是false
IsBlog bool `IsBlog,omitempty` // 是否是Blog 2013/12/29 新加
CreatedTime time.Time `CreatedTime,omitempty`
UpdatedTime time.Time `UpdatedTime,omitempty`
}笔记
- 笔记属于某个笔记本
- 笔记基本包括(标题, 描述, 图片(第一张缩略图), 多个标签, 内容)
- 笔记可以公开为博客
- 笔记可共享
- 笔记可删除(先作为trash, trash删除后真正删除)
- 支持markdown和html(以isMarkdown字段区分)
// Note表没有内容!!
type Note struct {
NoteId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
UserId bson.ObjectId `bson:"UserId"` // 谁的
CreatedUserId bson.ObjectId `bson:"CreatedUserId,omitempty"` // 谁创建的(UserId != CreatedUserId, 是因为共享). 只是共享才有, 默认为空, 不存 必须要加omitempty
NotebookId bson.ObjectId `bson:"NotebookId"`
Title string `Title` // 标题
Desc string `Desc` // 描述, 非html
ImgSrc string `ImgSrc` // 图片, 第一张缩略图地址
Tags []string `Tags,omitempty`
IsTrash bool `IsTrash` // 是否是trash, 默认是false
IsBlog bool `IsBlog,omitempty` // 是否设置成了blog 2013/12/29 新加
IsTop bool `IsTop,omitempty` // blog是否置顶 暂时没用
IsMarkdown bool `IsMarkdown` // 是否是markdown笔记, 默认是false
CreatedTime time.Time `CreatedTime`
UpdatedTime time.Time `UpdatedTime`
UpdatedUserId bson.ObjectId `bson:"UpdatedUserId"` // 如果共享了, 并可写, 那么可能是其它他修改了
}// 内容
type NoteContent struct {
NoteId bson.ObjectId `bson:"_id,omitempty"`
UserId bson.ObjectId `bson:"UserId"`
IsBlog bool `IsBlog,omitempty` // 为了搜索博客
Content string `Content` // 笔记内容
Abstract string `Abstract` // 摘要, 有html标签, 比content短, 在博客展示需要, 不放在notes表中
CreatedTime time.Time `CreatedTime`
UpdatedTime time.Time `UpdatedTime`
UpdatedUserId bson.ObjectId `bson:"UpdatedUserId"` // 如果共享了, 并可写, 那么可能是其它他修改了
}为什么要把内容与笔记基本信息分开? 因为速度...
分享/协作
- 可将笔记本, 笔记分享
- 若将笔记本分享, 则会将该笔记本下所有的笔记分享,
- 也可单独将笔记分享(或不分享)
主要3个表:
// 谁共享给了谁note
// 共享了note, notebook都要加!
type HasShareNote struct {
HasShareNotebookId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
UserId bson.ObjectId `bson:"UserId"`
ToUserId bson.ObjectId `bson:"ToUserId"`
Seq int `bson:"Seq"` // 以后还可以用户排序
}
// 共享的笔记
// 唯一: userId-ToUserId-NoteId
type ShareNote struct {
ShareNoteId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
UserId bson.ObjectId `bson:"UserId"`
ToUserId bson.ObjectId `bson:"ToUserId"`
NoteId bson.ObjectId `bson:"NoteId"`
Perm int `bson:"Perm"` // 权限, 0只读, 1可修改
CreatedTime time.Time `CreatedTime`
}
// 共享的笔记本
type ShareNotebook struct {
ShareNotebookId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
UserId bson.ObjectId `bson:"UserId"`
ToUserId bson.ObjectId `bson:"ToUserId"`
NotebookId bson.ObjectId `bson:"NotebookId"`
Seq int `bson:"Seq"` // 排序
Perm int `bson:"Perm"` // 权限, 其下所有notes 0只读, 1可修改
CreatedTime time.Time `CreatedTime,omitempty`
// IsDefault bool `IsDefault` // 是否是默认共享notebook, perm seq=-9999999, NotebookId=null
}博客
用户可设置博客的主题, logo, about me之类.
// 每个用户一份博客设置信息
type UserBlog struct {
UserId bson.ObjectId `bson:"_id"` // 谁的
Logo string `Logo`
Title string `Title` // 标题
SubTitle string `SubTitle` // 副标题
AboutMe string `AboutMe` // 关于我
CanComment bool `CanComment` // 是否可以评论
DisqusId string `DisqusId`
Style string `Style` // 风格
}
life
life