本文整理匯總了Golang中github.com/leanote/leanote/app/db.Get函數的典型用法代碼示例。如果您正苦於以下問題:Golang Get函數的具體用法?Golang Get怎麽用?Golang Get使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Get函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}
示例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
}
示例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"
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例11: GetSingle
func (this *BlogService) GetSingle(singleId string) info.BlogSingle {
page := info.BlogSingle{}
db.Get(db.BlogSingles, singleId, &page)
return page
}
示例12: GetUserBlog
func (this *BlogService) GetUserBlog(userId string) info.UserBlog {
userBlog := info.UserBlog{}
db.Get(db.UserBlogs, userId, &userBlog)
this.fixUserBlog(&userBlog)
return userBlog
}
示例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
}
示例14: GetUserInfo
// 得到用戶信息 userId
func (this *UserService) GetUserInfo(userId string) info.User {
user := info.User{}
db.Get(db.Users, userId, &user)
return user
}
示例15: GetTags
func (this *TagService) GetTags(userId string) []string {
tag := info.Tag{}
db.Get(db.Tags, userId, &tag)
LogJ(tag)
return tag.Tags
}