本文整理汇总了Golang中github.com/leanote/leanote/app/db.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: LikeComment
// 点赞/取消赞
func (this *BlogService) LikeComment(commentId, userId string) (ok bool, isILike bool, num int) {
ok = false
isILike = false
num = 0
comment := info.BlogComment{}
db.Get(db.BlogComments, commentId, &comment)
var n int
if comment.LikeUserIds != nil && len(comment.LikeUserIds) > 0 && InArray(comment.LikeUserIds, userId) {
n = -1
// 从点赞名单删除
db.Update(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)},
bson.M{"$pull": bson.M{"LikeUserIds": userId}})
isILike = false
} else {
n = 1
// 添加之
db.Update(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)},
bson.M{"$push": bson.M{"LikeUserIds": userId}})
isILike = true
}
if comment.LikeUserIds == nil {
num = 0
} else {
num = len(comment.LikeUserIds) + n
}
ok = db.Update(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)},
bson.M{"$set": bson.M{"LikeNum": num}})
return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:35,代码来源:BlogService.go
示例2: GetAttach
// 获取文件路径
// 要判断是否具有权限
// userId是否具有attach的访问权限
func (this *AttachService) GetAttach(attachId, userId string) (attach info.Attach) {
if attachId == "" {
return
}
attach = info.Attach{}
db.Get(db.Attachs, attachId, &attach)
path := attach.Path
if path == "" {
return
}
note := noteService.GetNoteById(attach.NoteId.Hex())
// 判断权限
// 笔记是否是公开的
if note.IsBlog {
return
}
// 笔记是否是我的
if note.UserId.Hex() == userId {
return
}
// 我是否有权限查看或协作
if shareService.HasReadNotePerm(attach.NoteId.Hex(), userId) {
return
}
attach = info.Attach{}
return
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:37,代码来源:AttachService.go
示例3: GetUserInfo
// 得到用户信息 userId
func (this *UserService) GetUserInfo(userId string) info.User {
user := info.User{}
db.Get(db.Users, userId, &user)
// Logo路径问题, 有些有http: 有些没有
this.setUserLogo(&user)
return user
}
开发者ID:rainkong,项目名称:leanote,代码行数:8,代码来源:UserService.go
示例4: DeleteAttach
// delete attach
func (this *AttachService) DeleteAttach(attachId, userId string) (bool, string) {
attach := info.Attach{}
db.Get(db.Attachs, attachId, &attach)
if(attach.AttachId != "") {
// 判断是否有权限为笔记添加附件
if !shareService.HasUpdateNotePerm(attach.NoteId.Hex(), userId) {
return false, "No Perm"
}
if db.Delete(db.Attachs, bson.M{"_id": bson.ObjectIdHex(attachId)}) {
this.updateNoteAttachNum(attach.NoteId, -1)
attach.Path = strings.TrimLeft(attach.Path, "/")
err := os.Remove(revel.BasePath + "/" + attach.Path)
if err == nil {
// userService.UpdateAttachSize(note.UserId.Hex(), -attach.Size)
// 修改note Usn
noteService.IncrNoteUsn(attach.NoteId.Hex(), userId)
return true, "delete file success"
}
return false, "delete file error"
}
return false, "db error"
}
return false, "no such item"
}
开发者ID:intZz,项目名称:leanote,代码行数:28,代码来源:AttachService.go
示例5: GetSingleByUserIdAndUrlTitle
func (this *BlogService) GetSingleByUserIdAndUrlTitle(userId, singleIdOrUrlTitle string) info.BlogSingle {
page := info.BlogSingle{}
if IsObjectId(singleIdOrUrlTitle) {
db.Get(db.BlogSingles, singleIdOrUrlTitle, &page)
} else {
db.GetByQ(db.BlogSingles, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(singleIdOrUrlTitle)}, &page)
}
return page
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:9,代码来源:BlogService.go
示例6: GetNotebookByUserIdAndUrlTitle
func (this *NotebookService) GetNotebookByUserIdAndUrlTitle(userId, notebookIdOrUrlTitle string) info.Notebook {
notebook := info.Notebook{}
if IsObjectId(notebookIdOrUrlTitle) {
db.Get(db.Notebooks, notebookIdOrUrlTitle, ¬ebook)
} else {
db.GetByQ(db.Notebooks, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(notebookIdOrUrlTitle)}, ¬ebook)
}
return notebook
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:9,代码来源:NotebookService.go
示例7: GetShareNoteContent
// 得到共享的笔记内容
// 首先要判断这个note是否我被共享了
func (this *ShareService) GetShareNoteContent(noteId, myUserId, sharedUserId string) (noteContent info.NoteContent) {
noteContent = info.NoteContent{}
// 是否单独共享了该notebook
// 或者, 其notebook共享了我
if this.hasSharedNote(noteId, myUserId) || this.hasSharedNotebook(noteId, myUserId, sharedUserId) {
db.Get(db.NoteContents, noteId, ¬eContent)
} else {
}
return
}
开发者ID:bigxing,项目名称:leanote,代码行数:12,代码来源:ShareService.go
示例8: GetUserBlog
//------------------------
// 博客设置
func (this *BlogService) GetUserBlog(userId string) info.UserBlog {
userBlog := info.UserBlog{}
db.Get(db.UserBlogs, userId, &userBlog)
if userBlog.Title == "" {
userInfo := userService.GetUserInfo(userId)
userBlog.Title = userInfo.Username + " 的博客"
}
return userBlog
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:13,代码来源:BlogService.go
示例9: Comment
// 评论
// 在noteId博客下userId 给toUserId评论content
// commentId可为空(针对某条评论评论)
func (this *BlogService) Comment(noteId, toCommentId, userId, content string) (bool, info.BlogComment) {
var comment info.BlogComment
if content == "" {
return false, comment
}
note := noteService.GetNoteById(noteId)
if !note.IsBlog {
return false, comment
}
comment = info.BlogComment{CommentId: bson.NewObjectId(),
NoteId: bson.ObjectIdHex(noteId),
UserId: bson.ObjectIdHex(userId),
Content: content,
CreatedTime: time.Now(),
}
var comment2 = info.BlogComment{}
if toCommentId != "" {
comment2 = info.BlogComment{}
db.Get(db.BlogComments, toCommentId, &comment2)
if comment2.CommentId != "" {
comment.ToCommentId = comment2.CommentId
comment.ToUserId = comment2.UserId
}
} else {
// comment.ToUserId = note.UserId
}
ok := db.Insert(db.BlogComments, comment)
if ok {
// 评论+1
db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": 1}})
}
if userId != note.UserId.Hex() || toCommentId != "" {
go func() {
this.sendEmail(note, comment2, userId, content)
}()
}
return ok, comment
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:45,代码来源:BlogService.go
示例10: DeleteComment
// 作者(或管理员)可以删除所有评论
// 自己可以删除评论
func (this *BlogService) DeleteComment(noteId, commentId, userId string) bool {
note := noteService.GetNoteById(noteId)
if !note.IsBlog {
return false
}
comment := info.BlogComment{}
db.Get(db.BlogComments, commentId, &comment)
if comment.CommentId == "" {
return false
}
if userId == configService.GetAdminUserId() || note.UserId.Hex() == userId || comment.UserId.Hex() == userId {
if db.Delete(db.BlogComments, bson.M{"_id": bson.ObjectIdHex(commentId)}) {
// 评论-1
db.Update(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId)}, bson.M{"$inc": bson.M{"CommentNum": -1}})
return true
}
}
return false
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:25,代码来源:BlogService.go
示例11: GetSingle
func (this *BlogService) GetSingle(singleId string) info.BlogSingle {
page := info.BlogSingle{}
db.Get(db.BlogSingles, singleId, &page)
return page
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:5,代码来源:BlogService.go
示例12: GetUserBlog
func (this *BlogService) GetUserBlog(userId string) info.UserBlog {
userBlog := info.UserBlog{}
db.Get(db.UserBlogs, userId, &userBlog)
this.fixUserBlog(&userBlog)
return userBlog
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:6,代码来源:BlogService.go
示例13: GetNotebookId
// 通过noteId得到notebookId
// shareService call
// [ok]
func (this *NoteService) GetNotebookId(noteId string) bson.ObjectId {
note := &info.Note{}
db.Get(db.Notes, noteId, note)
return note.NotebookId
}
开发者ID:jianping11,项目名称:leanote,代码行数:8,代码来源:NoteService.go
示例14: GetUserInfo
// 得到用户信息 userId
func (this *UserService) GetUserInfo(userId string) info.User {
user := info.User{}
db.Get(db.Users, userId, &user)
return user
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:6,代码来源:UserService.go
示例15: GetTags
func (this *TagService) GetTags(userId string) []string {
tag := info.Tag{}
db.Get(db.Tags, userId, &tag)
LogJ(tag)
return tag.Tags
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:6,代码来源:TagService.go
示例16: GetFile
// 获取文件路径
// 要判断是否具有权限
// userId是否具有fileId的访问权限
func (this *FileService) GetFile(userId, fileId string) string {
if fileId == "" {
return ""
}
file := info.File{}
db.Get(db.Files, fileId, &file)
path := file.Path
if path == "" {
return ""
}
// 1. 判断权限
// 是否是我的文件
if userId != "" && file.UserId.Hex() == userId {
return path
}
// 得到使用过该fileId的所有笔记NoteId
// 这些笔记是否有public的, 若有则ok
// 这些笔记(笔记本)是否有共享给我的, 若有则ok
noteIds := noteImageService.GetNoteIds(fileId)
if noteIds != nil && len(noteIds) > 0 {
// 这些笔记是否有public的
if db.Has(db.Notes, bson.M{"_id": bson.M{"$in": noteIds}, "IsBlog": true}) {
return path
}
// 2014/12/28 修复, 如果是分享给用户组, 那就不行, 这里可以实现
for _, noteId := range noteIds {
note := noteService.GetNoteById(noteId.Hex())
if shareService.HasReadPerm(note.UserId.Hex(), userId, noteId.Hex()) {
return path
}
}
/*
// 若有共享给我的笔记?
// 对该笔记可读?
if db.Has(db.ShareNotes, bson.M{"ToUserId": bson.ObjectIdHex(userId), "NoteId": bson.M{"$in": noteIds}}) {
return path
}
// 笔记本是否共享给我?
// 通过笔记得到笔记本
notes := []info.Note{}
db.ListByQWithFields(db.Notes, bson.M{"_id": bson.M{"$in": noteIds}}, []string{"NotebookId"}, ¬es)
if notes != nil && len(notes) > 0 {
notebookIds := make([]bson.ObjectId, len(notes))
for i := 0; i < len(notes); i++ {
notebookIds[i] = notes[i].NotebookId
}
if db.Has(db.ShareNotebooks, bson.M{"ToUserId": bson.ObjectIdHex(userId), "NotebookId": bson.M{"$in": notebookIds}}) {
return path
}
}
*/
}
// 可能是刚复制到owner上, 但内容又没有保存, 所以没有note->imageId的映射, 此时看是否有fromFileId
if file.FromFileId != "" {
fromFile := info.File{}
db.Get2(db.Files, file.FromFileId, &fromFile)
if fromFile.UserId.Hex() == userId {
return fromFile.Path
}
}
return ""
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:75,代码来源:FileService.go
示例17: GetNotebookById
func (this *NotebookService) GetNotebookById(notebookId string) info.Notebook {
notebook := info.Notebook{}
db.Get(db.Notebooks, notebookId, ¬ebook)
return notebook
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:5,代码来源:NotebookService.go
示例18: GetNoteById
// fileService调用
func (this *NoteService) GetNoteById(noteId string) (note info.Note) {
note = info.Note{}
db.Get(db.Notes, noteId, ¬e)
return
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:6,代码来源:NoteService.go
注:本文中的github.com/leanote/leanote/app/db.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论