init
This commit is contained in:
1 parent
fac05a7b6c
commit
476ade10e7
1085 files changed
+259628
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
// 只为blog, 不为note
|
||||
|
||||
type BlogItem struct {
|
||||
Note
|
||||
Content string // 可能是content的一部分, 截取. 点击more后就是整个信息了
|
||||
HasMore bool // 是否是否还有
|
||||
}
|
||||
|
||||
type UserBlogBase struct {
|
||||
Logo string `Logo`
|
||||
Title string `Title` // 标题
|
||||
SubTitle string `SubTitle` // 副标题
|
||||
AboutMe string `AboutMe` // 关于我
|
||||
}
|
||||
|
||||
type UserBlogComment struct {
|
||||
CanComment bool `CanComment` // 是否可以评论
|
||||
DisqusId string `DisqusId`
|
||||
}
|
||||
|
||||
type UserBlogStyle struct {
|
||||
Style string `Style` // 风格
|
||||
}
|
||||
|
||||
// 每个用户一份博客设置信息
|
||||
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` // 风格
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 只存笔记基本信息
|
||||
// 内容不存放
|
||||
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"` // 如果共享了, 并可写, 那么可能是其它他修改了
|
||||
}
|
||||
|
||||
// 基本信息和内容在一起
|
||||
type NoteAndContent struct {
|
||||
Note
|
||||
NoteContent
|
||||
}
|
||||
|
||||
// 历史记录
|
||||
// 每一个历史记录对象
|
||||
type EachHistory struct {
|
||||
UpdatedUserId bson.ObjectId `UpdatedUserId`
|
||||
UpdatedTime time.Time `UpdatedTime`
|
||||
Content string `Content`
|
||||
}
|
||||
type NoteContentHistory struct {
|
||||
NoteId bson.ObjectId `bson:"_id,omitempty"`
|
||||
UserId bson.ObjectId `bson:"UserId"` // 所属者
|
||||
Histories []EachHistory `Histories`
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"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` // 标题
|
||||
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`
|
||||
}
|
||||
|
||||
// 仅仅是为了返回前台
|
||||
type SubNotebooks []Notebooks
|
||||
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 {
|
||||
return this[i].Seq < this[j].Seq
|
||||
}
|
||||
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
|
||||
*/
|
||||
@@ -0,0 +1 @@
|
||||
All the mgo model and common struct
|
||||
@@ -0,0 +1,18 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
// controller ajax返回
|
||||
type Re struct {
|
||||
Ok bool
|
||||
Code int
|
||||
Msg string
|
||||
Id string
|
||||
List interface{}
|
||||
Item interface{}
|
||||
}
|
||||
|
||||
func NewRe() Re {
|
||||
return Re{Ok: false}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 共享笔记本
|
||||
/*
|
||||
{
|
||||
userId, 谁的共享笔记本
|
||||
shared: {
|
||||
userId1: { // 哪个用户共享的
|
||||
seq:
|
||||
"defaultNotebook": {noteId:{Seq:33}, noteId2:{}} // 默认笔记本, 里面是全部的笔记
|
||||
"notebookIds":{notebookId:{}, notebookId2:{}}} // 其它笔记本
|
||||
},
|
||||
userId2: {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// 以后可能含有其它信息
|
||||
type EachSharedNote struct {
|
||||
Seq int
|
||||
}
|
||||
type EachSharedNotebook struct {
|
||||
Seq int
|
||||
}
|
||||
|
||||
// 每一个用户共享给的note, notebook
|
||||
type EachSharedNotebookAndNotes struct {
|
||||
Seq int // 共享给谁的所在序号
|
||||
DefaultNotebook map[string]EachSharedNote // noteId => 共享的note
|
||||
Notebooks map[string]EachSharedNotebook // notebookId => 共享的notebook
|
||||
}
|
||||
|
||||
type SharedNotebookAndNotes struct {
|
||||
UserId bson.ObjectId `bson:"_id"`
|
||||
Shared map[string]EachSharedNotebookAndNotes // userId =>
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
UserId
|
||||
Notes: {noteId => [userId1, userId2], noteId2: []}
|
||||
Notebooks: {notebookId => [], notebookId2 => []}
|
||||
}
|
||||
*/
|
||||
|
||||
// 用户正在共享的notebook, note
|
||||
type SharingNotebookAndNotes struct {
|
||||
UserId bson.ObjectId `bson:"_id"`
|
||||
Notes map[string][]string // noteId => []string{userId1, userId2}
|
||||
Notebooks map[string][]string // notebookId => []string{userId1, userId2}
|
||||
}
|
||||
|
||||
// 以上以后再用, 现不用
|
||||
//----------------------------------------
|
||||
|
||||
/*
|
||||
每一个sharing一条记录, 这样更好操作
|
||||
类似Notebook的
|
||||
{
|
||||
_id
|
||||
userId
|
||||
toUserId
|
||||
noteId
|
||||
notebookId
|
||||
seq
|
||||
}
|
||||
*/
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/*
|
||||
[
|
||||
ShareNotebooks,
|
||||
Subs: [ShareNotebooks, ]
|
||||
ShareNotebooks
|
||||
]
|
||||
*/
|
||||
type SubShareNotebooks []ShareNotebooks
|
||||
type ShareNotebooks struct {
|
||||
Notebook
|
||||
ShareNotebook
|
||||
Subs SubShareNotebooks
|
||||
|
||||
// Notebook与ShareNotebook公用的不能生成json
|
||||
Seq int
|
||||
NotebookId bson.ObjectId
|
||||
IsDefault bool // 是否是默认笔记本
|
||||
}
|
||||
|
||||
// SubShareNotebook sort
|
||||
func (this SubShareNotebooks) Len() int {
|
||||
return len(this)
|
||||
}
|
||||
func (this SubShareNotebooks) Less(i, j int) bool {
|
||||
return this[i].ShareNotebook.Seq < this[j].ShareNotebook.Seq
|
||||
}
|
||||
func (this SubShareNotebooks) Swap(i, j int) {
|
||||
this[i], this[j] = this[j], this[i]
|
||||
}
|
||||
|
||||
// 以用户进行分组
|
||||
// type ShareNotebooksByUsers []ShareNotebooksByUser
|
||||
type ShareNotebooksByUser map[string][]ShareNotebooks
|
||||
|
||||
/*
|
||||
type ShareNotebooksByUser struct {
|
||||
// User
|
||||
UserId bson.ObjectId
|
||||
ShareNotebooks []ShareNotebooks // SubShareNotebooks 一样的, 不过用[]更容易理解
|
||||
}
|
||||
*/
|
||||
|
||||
//----------------------------------
|
||||
|
||||
// 唯一: userId-ToUserId-NoteId
|
||||
// use leanote
|
||||
// db.leanote.share_notes.ensureIndex({"UserId":1,"ToUserId":1, "NoteId": 1},{"unique":true})
|
||||
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`
|
||||
}
|
||||
|
||||
// 谁共享给了谁note
|
||||
// 共享了note, notebook都要加!
|
||||
// 唯一: UserId-ToUserId
|
||||
// db.leanote.has_share_notes.ensureIndex({"UserId":1,"ToUserId":1},{"unique":true})
|
||||
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"` // 以后还可以用户排序
|
||||
}
|
||||
|
||||
// 将note与权限结合起来
|
||||
type ShareNoteWithPerm struct {
|
||||
Note
|
||||
Perm int
|
||||
}
|
||||
|
||||
// 查看共享状态, 用户的信息
|
||||
type ShareUserInfo struct {
|
||||
ToUserId bson.ObjectId `bson:"UserId"`
|
||||
Email string
|
||||
Perm int // note或其notebook的权限
|
||||
NotebookHasShared bool // 是否其notebook共享了
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
// 建议
|
||||
type Suggestion struct {
|
||||
Id bson.ObjectId `bson:"_id"`
|
||||
UserId bson.ObjectId `UserId`
|
||||
Addr string `Addr`
|
||||
Suggestion string `Suggestion`
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
)
|
||||
|
||||
// 这里主要是为了统计每个tag的note数目
|
||||
type TagNote struct {
|
||||
TagId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
|
||||
UserId bson.ObjectId `bson:"UserId"`
|
||||
Tag string `Title` // 标题
|
||||
NoteNum int `NoteNum` // note数目
|
||||
}
|
||||
|
||||
// 每个用户一条记录, 存储用户的所有tags
|
||||
type Tag struct {
|
||||
UserId bson.ObjectId `bson:"_id"`
|
||||
Tags []string `Tags`
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 随机token
|
||||
// 验证邮箱
|
||||
// 找回密码
|
||||
|
||||
// token type
|
||||
const (
|
||||
TokenPwd = iota
|
||||
TokenActiveEmail
|
||||
TokenUpdateEmail
|
||||
)
|
||||
|
||||
// 过期时间
|
||||
const (
|
||||
PwdOverHours = 2.0
|
||||
ActiveEmailOverHours = 48.0
|
||||
UpdateEmailOverHours = 2.0
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
UserId bson.ObjectId `bson:"_id"`
|
||||
Email string `Email`
|
||||
Token string `Token`
|
||||
Type int `Type`
|
||||
CreatedTime time.Time `CreatedTime`
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
"labix.org/v2/mgo/bson"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 第三方类型
|
||||
const (
|
||||
ThirdGithub = iota
|
||||
ThirdQQ
|
||||
)
|
||||
|
||||
type User struct {
|
||||
UserId bson.ObjectId `bson:"_id,omitempty"` // 必须要设置bson:"_id" 不然mgo不会认为是主键
|
||||
Email string `Email` // 全是小写
|
||||
Verified bool `Verified` // Email是否已验证过?
|
||||
Username string `Username` // 不区分大小写, 全是小写
|
||||
UsernameRaw string `UsernameRaw` // 可能有大小写
|
||||
Pwd string `bson:"Pwd" json:"-"`
|
||||
CreatedTime time.Time `CreatedTime`
|
||||
|
||||
// 主题
|
||||
Theme string `Theme`
|
||||
|
||||
// 用户配置
|
||||
NotebookWidth int `NotebookWidth` // 笔记本宽度
|
||||
NoteListWidth int `NoteListWidth` // 笔记列表宽度
|
||||
LeftIsMin bool `LeftIsMin` // 左侧是否是隐藏的, 默认是打开的
|
||||
|
||||
// 这里 第三方登录
|
||||
ThirdUserId string `ThirdUserId` // 用户Id, 在第三方中唯一可识别
|
||||
ThirdUsername string `ThirdUsername` // 第三方中username, 为了显示
|
||||
ThirdType int `ThirdType` // 第三方类型
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package info
|
||||
|
||||
import (
|
||||
)
|
||||
|
||||
|
||||
// 分页数据
|
||||
type Page struct {
|
||||
CurPage int // 当前页码
|
||||
TotalPage int // 总页
|
||||
List interface{}
|
||||
}
|
||||
Reference in new issue
Block a user