Files
leanote/app/info/Api.go

120 lines
2.7 KiB
Go
Raw Normal View History

2015-03-31 14:27:26 +08:00
package info
import (
"gopkg.in/mgo.v2/bson"
2015-11-13 17:58:41 +08:00
"time"
2015-03-31 14:27:26 +08:00
)
//---------
// 数据结构
//---------
type NoteFile struct {
2015-11-13 17:58:41 +08:00
FileId string // 服务器端Id
2015-03-31 14:27:26 +08:00
LocalFileId string // 客户端Id
2015-11-13 17:58:41 +08:00
Type string // images/png, doc, xls, 根据fileName确定
Title string
HasBody bool // 传过来的值是否要更新内容
IsAttach bool // 是否是附件, 不是附件就是图片
2015-03-31 14:27:26 +08:00
}
type ApiNote struct {
NoteId string
NotebookId string
UserId string
Title string
Desc string
2015-11-13 17:58:41 +08:00
// ImgSrc string
2015-03-31 14:27:26 +08:00
Tags []string
Abstract string
Content string
IsMarkdown bool
2015-11-13 17:58:41 +08:00
// FromUserId string // 为共享而新建
IsBlog bool // 是否是blog, 更新note不需要修改, 添加note时才有可能用到, 此时需要判断notebook是否设为Blog
IsTrash bool
IsDeleted bool
Usn int
Files []NoteFile
2015-03-31 14:27:26 +08:00
CreatedTime time.Time
UpdatedTime time.Time
2015-11-13 17:58:41 +08:00
PublicTime time.Time
2015-03-31 14:27:26 +08:00
}
// 内容
type ApiNoteContent struct {
NoteId bson.ObjectId `bson:"_id,omitempty"`
UserId bson.ObjectId `bson:"UserId"`
2015-11-13 17:58:41 +08:00
Content string `Content`
2015-03-31 14:27:26 +08:00
2015-11-13 17:58:41 +08:00
// CreatedTime time.Time `CreatedTime`
// UpdatedTime time.Time `UpdatedTime`
2015-03-31 14:27:26 +08:00
}
// 转换
func NoteToApiNote(note Note, files []NoteFile) ApiNote {
apiNote := ApiNote{}
return apiNote
}
//----------
// 用户信息
//----------
type ApiUser struct {
2015-11-13 17:58:41 +08:00
UserId string
2015-03-31 14:27:26 +08:00
Username string
2015-11-13 17:58:41 +08:00
Email string
2015-03-31 14:27:26 +08:00
Verified bool
2015-11-13 17:58:41 +08:00
Logo string
2015-03-31 14:27:26 +08:00
}
//----------
// Notebook
//----------
type ApiNotebook 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` // 标题
UrlTitle string `UrlTitle` // Url标题 2014/11.11加
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
Usn int `Usn` // UpdateSequenceNum
IsDeleted bool `IsDeleted`
2015-03-31 14:27:26 +08:00
}
//---------
// api 返回
//---------
// 一般返回
type ApiRe struct {
2015-11-13 17:58:41 +08:00
Ok bool
2015-03-31 14:27:26 +08:00
Msg string
}
func NewApiRe() ApiRe {
return ApiRe{Ok: false}
}
// auth
type AuthOk struct {
2015-11-13 17:58:41 +08:00
Ok bool
Token string
UserId bson.ObjectId
Email string
2015-03-31 14:27:26 +08:00
Username string
}
// 供notebook, note, tag更新的返回数据用
type ReUpdate struct {
2015-11-13 17:58:41 +08:00
Ok bool
2015-03-31 14:27:26 +08:00
Msg string
Usn int
}
2015-11-13 17:58:41 +08:00
2015-03-31 14:27:26 +08:00
func NewReUpdate() ReUpdate {
return ReUpdate{Ok: false}
2015-11-13 17:58:41 +08:00
}