本文整理汇总了Golang中github.com/leanote/leanote/app/db.UpdateByIdAndUserIdMap函数的典型用法代码示例。如果您正苦于以下问题:Golang UpdateByIdAndUserIdMap函数的具体用法?Golang UpdateByIdAndUserIdMap怎么用?Golang UpdateByIdAndUserIdMap使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UpdateByIdAndUserIdMap函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UpdateNote
// 修改笔记
// [ok] TODO perm还没测
func (this *NoteService) UpdateNote(userId, updatedUserId, noteId string, needUpdate bson.M) bool {
// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
if userId != updatedUserId {
if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
Log("NO AUTH")
return false
} else {
Log("HAS AUTH -----------")
}
}
needUpdate["UpdatedUserId"] = bson.ObjectIdHex(updatedUserId)
needUpdate["UpdatedTime"] = time.Now()
// 添加tag2
if tags, ok := needUpdate["Tags"]; ok {
tagService.AddTagsI(userId, tags)
}
// 是否修改了isBlog
// 也要修改noteContents的IsBlog
if isBlog, ok := needUpdate["IsBlog"]; ok {
db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, bson.M{"IsBlog": isBlog})
}
return db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, needUpdate)
}
开发者ID:jianping11,项目名称:leanote,代码行数:29,代码来源:NoteService.go
示例2: UpateBlogAbstract
// 修改博客的图片, 描述, 摘要
func (this *BlogService) UpateBlogAbstract(userId string, noteId, imgSrc, desc, abstract string) (ok bool) {
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, bson.M{
"ImgSrc": imgSrc,
"Desc": desc,
"HasSelfDefined": true,
})
ok = db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, bson.M{
"Abstract": abstract,
})
return ok
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:12,代码来源:BlogService.go
示例3: UpateBlogUrlTitle
// 修改笔记urlTitle
func (this *BlogService) UpateBlogUrlTitle(userId string, noteId, urlTitle string) (ok bool, url string) {
url = urlTitle
// 先清空
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, bson.M{
"UrlTitle": "",
})
url = GetUrTitle(userId, urlTitle, "note", noteId)
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, bson.M{
"UrlTitle": url,
})
// 返回给前端的是decode
url = decodeValue(url)
return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:15,代码来源:BlogService.go
示例4: DeleteTrashApi
func (this *TrashService) DeleteTrashApi(noteId, userId string, usn int) (bool, string, int) {
note := noteService.GetNote(noteId, userId)
if note.NoteId == "" || note.IsDeleted {
return false, "notExists", 0
}
if note.Usn != usn {
return false, "conflict", 0
}
// delete note's attachs
ok := attachService.DeleteAllAttachs(noteId, userId)
// 设置删除位
afterUsn := userService.IncrUsn(userId)
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId,
bson.M{"IsDeleted": true,
"Usn": afterUsn})
// delete content
ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId)
// 删除content history
ok = db.DeleteByIdAndUserId(db.NoteContentHistories, noteId, userId)
// 一个BUG, iOS删除直接调用这个API, 结果没有重新recount
// recount notebooks' notes number
notebookService.ReCountNotebookNumberNotes(note.NotebookId.Hex())
return ok, "", afterUsn
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:32,代码来源:TrashService.go
示例5: UpdateNoteContent
// 修改笔记本内容
// [ok] TODO perm未测
func (this *NoteService) UpdateNoteContent(userId, updatedUserId, noteId, content, abstract string) bool {
// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
if userId != updatedUserId {
if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
Log("NO AUTH")
return false
}
}
data := bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId),
"Content": content,
"Abstract": abstract,
"UpdatedTime": time.Now()}
// 是否已自定义
note := this.GetNoteById(noteId)
if note.IsBlog && note.HasSelfDefined {
delete(data, "Abstract")
}
if db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, data) {
// 这里, 添加历史记录
noteContentHistoryService.AddHistory(noteId, userId, info.EachHistory{UpdatedUserId: bson.ObjectIdHex(updatedUserId),
Content: content,
UpdatedTime: time.Now(),
})
// 更新笔记图片
noteImageService.UpdateNoteImages(userId, noteId, note.ImgSrc, content)
return true
}
return false
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:36,代码来源:NoteService.go
示例6: DeleteTrashApi
func (this *TrashService) DeleteTrashApi(noteId, userId string, usn int) (bool, string, int) {
note := noteService.GetNote(noteId, userId)
if note.NoteId == "" || note.IsDeleted {
return false, "notExists", 0
}
if note.Usn != usn {
return false, "conflict", 0
}
// delete note's attachs
ok := attachService.DeleteAllAttachs(noteId, userId)
// 设置删除位
afterUsn := userService.IncrUsn(userId)
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId,
bson.M{"IsDeleted": true,
"Usn": afterUsn})
// delete content
ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId)
return ok, "", afterUsn
}
开发者ID:howardroark2018,项目名称:leanote-all,代码行数:25,代码来源:TrashService.go
示例7: AddOrUpdateSingle
// 更新或添加
func (this *BlogService) AddOrUpdateSingle(userId, singleId, title, content string) (ok bool) {
ok = false
if singleId != "" {
ok = db.UpdateByIdAndUserIdMap(db.BlogSingles, singleId, userId, bson.M{
"Title": title,
"Content": content,
"UpdatedTime": time.Now(),
})
if ok {
// 还要修改UserBlog中的Singles
this.updateBlogSingles(userId, false, false, singleId, title, "")
}
return
}
// 添加
page := info.BlogSingle{
SingleId: bson.NewObjectId(),
UserId: bson.ObjectIdHex(userId),
Title: title,
Content: content,
UrlTitle: GetUrTitle(userId, title, "single", singleId),
CreatedTime: time.Now(),
}
page.UpdatedTime = page.CreatedTime
ok = db.Insert(db.BlogSingles, page)
// 还要修改UserBlog中的Singles
this.updateBlogSingles(userId, false, true, page.SingleId.Hex(), title, page.UrlTitle)
return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:32,代码来源:BlogService.go
示例8: DeleteTrash
// 删除trash
func (this *TrashService) DeleteTrash(noteId, userId string) bool {
note := noteService.GetNote(noteId, userId)
if note.NoteId == "" {
return false
}
// delete note's attachs
ok := attachService.DeleteAllAttachs(noteId, userId)
// 设置删除位
ok = db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId,
bson.M{"IsDeleted": true,
"Usn": userService.IncrUsn(userId)})
// delete note
// ok = db.DeleteByIdAndUserId(db.Notes, noteId, userId)
// delete content
ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId)
// 删除content history
ok = db.DeleteByIdAndUserId(db.NoteContentHistories, noteId, userId)
// 重新统计tag's count
// TODO 这里会改变tag's Usn
tagService.reCountTagCount(userId, note.Tags)
return ok
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:28,代码来源:TrashService.go
示例9: ToBlog
// ToBlog or Not
func (this *NotebookService) ToBlog(userId, notebookId string, isBlog bool) bool {
// 笔记本
db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"IsBlog": isBlog})
// 更新笔记
q := bson.M{"UserId": bson.ObjectIdHex(userId),
"NotebookId": bson.ObjectIdHex(notebookId)}
data := bson.M{"IsBlog": isBlog}
if isBlog {
data["PublicTime"] = time.Now()
} else {
data["HasSelfDefined"] = false
}
db.UpdateByQMap(db.Notes, q, data)
// noteContents也更新, 这个就麻烦了, noteContents表没有NotebookId
// 先查该notebook下所有notes, 得到id
notes := []info.Note{}
db.ListByQWithFields(db.Notes, q, []string{"_id"}, ¬es)
if len(notes) > 0 {
noteIds := make([]bson.ObjectId, len(notes))
for i, each := range notes {
noteIds[i] = each.NoteId
}
db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
}
// 重新计算tags
go (func() {
blogService.ReCountBlogTags(userId)
})()
return true
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:35,代码来源:NotebookService.go
示例10: UpdateNotebook
// 更新notebook
func (this *NotebookService) UpdateNotebook(userId, notebookId string, needUpdate bson.M) bool {
needUpdate["UpdatedTime"] = time.Now()
// 如果有IsBlog之类的, 需要特殊处理
if isBlog, ok := needUpdate["IsBlog"]; ok {
// 设为blog/取消
if is, ok2 := isBlog.(bool); ok2 {
q := bson.M{"UserId": bson.ObjectIdHex(userId),
"NotebookId": bson.ObjectIdHex(notebookId)}
db.UpdateByQMap(db.Notes, q, bson.M{"IsBlog": is})
// noteContents也更新, 这个就麻烦了, noteContents表没有NotebookId
// 先查该notebook下所有notes, 得到id
notes := []info.Note{}
db.ListByQWithFields(db.Notes, q, []string{"_id"}, ¬es)
if len(notes) > 0 {
noteIds := make([]bson.ObjectId, len(notes))
for i, each := range notes {
noteIds[i] = each.NoteId
}
db.UpdateByQMap(db.NoteContents, bson.M{"_id": bson.M{"$in": noteIds}}, bson.M{"IsBlog": isBlog})
}
}
}
return db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, needUpdate)
}
开发者ID:hello-kukoo,项目名称:leanote,代码行数:28,代码来源:NotebookService.go
示例11: ToBlog
func (this *NoteService) ToBlog(userId, noteId string, isBlog, isTop bool) bool {
noteUpdate := bson.M{}
if isTop {
isBlog = true
}
if !isBlog {
isTop = false
}
noteUpdate["IsBlog"] = isBlog
noteUpdate["IsTop"] = isTop
if isBlog {
noteUpdate["PublicTime"] = time.Now()
} else {
noteUpdate["HasSelfDefined"] = false
}
noteUpdate["Usn"] = userService.IncrUsn(userId)
ok := db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId, noteUpdate)
// 重新计算tags
go (func() {
this.UpdateNoteContentIsBlog(noteId, userId, isBlog)
blogService.ReCountBlogTags(userId)
})()
return ok
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:26,代码来源:NoteService.go
示例12: UpdateNotebookApi
// 更新笔记, api
func (this *NotebookService) UpdateNotebookApi(userId, notebookId, title, parentNotebookId string, seq, usn int) (bool, string, info.Notebook) {
if notebookId == "" {
return false, "notebookIdNotExists", info.Notebook{}
}
// 先判断usn是否和数据库的一样, 如果不一样, 则冲突, 不保存
notebook := this.GetNotebookById(notebookId)
// 不存在
if notebook.NotebookId == "" {
return false, "notExists", notebook
} else if notebook.Usn != usn {
return false, "conflict", notebook
}
notebook.Usn = userService.IncrUsn(userId)
notebook.Title = title
updates := bson.M{"Title": title, "Usn": notebook.Usn, "Seq": seq, "UpdatedTime": time.Now()}
if parentNotebookId != "" && bson.IsObjectIdHex(parentNotebookId) {
updates["ParentNotebookId"] = bson.ObjectIdHex(parentNotebookId)
} else {
updates["ParentNotebookId"] = ""
}
ok := db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, updates)
if ok {
return ok, "", this.GetNotebookById(notebookId)
}
return false, "", notebook
}
开发者ID:intZz,项目名称:leanote,代码行数:29,代码来源:NotebookService.go
示例13: UpdateNoteContent
// 修改笔记本内容
// [ok] TODO perm未测
// hasBeforeUpdateNote 之前是否更新过note其它信息, 如果有更新, usn不用更新
// TODO abstract这里生成
func (this *NoteService) UpdateNoteContent(updatedUserId, noteId, content, abstract string,
hasBeforeUpdateNote bool,
usn int, updatedTime time.Time) (bool, string, int) {
// 是否已自定义
note := this.GetNoteById(noteId)
if note.NoteId == "" {
return false, "notExists", 0
}
userId := note.UserId.Hex()
// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
if userId != updatedUserId {
if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
Log("NO AUTH")
return false, "noAuth", 0
}
}
updatedTime = FixUrlTime(updatedTime)
// abstract重置
data := bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId),
"Content": content,
"Abstract": abstract,
"UpdatedTime": updatedTime}
if note.IsBlog && note.HasSelfDefined {
delete(data, "Abstract")
}
// usn, 修改笔记不可能单独修改内容
afterUsn := 0
// 如果之前没有修改note其它信息, 那么usn++
if !hasBeforeUpdateNote {
// 需要验证
if usn >= 0 && note.Usn != usn {
return false, "conflict", 0
}
afterUsn = userService.IncrUsn(userId)
db.UpdateByIdAndUserIdField(db.Notes, noteId, userId, "Usn", usn)
}
if db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, data) {
// 这里, 添加历史记录
noteContentHistoryService.AddHistory(noteId, userId, info.EachHistory{UpdatedUserId: bson.ObjectIdHex(updatedUserId),
Content: content,
UpdatedTime: time.Now(),
})
// 更新笔记图片
noteImageService.UpdateNoteImages(userId, noteId, note.ImgSrc, content)
return true, "", afterUsn
}
return false, "", 0
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:59,代码来源:NoteService.go
示例14: UpdateNoteTitle
// 这里要判断权限, 如果userId != updatedUserId, 那么需要判断权限
// [ok] TODO perm还没测 [del]
func (this *NoteService) UpdateNoteTitle(userId, updatedUserId, noteId, title string) bool {
// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
if userId != updatedUserId {
if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
println("NO AUTH")
return false
}
}
return db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId,
bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId), "Title": title, "UpdatedTime": time.Now()})
}
开发者ID:jianping11,项目名称:leanote,代码行数:14,代码来源:NoteService.go
示例15: SortNotebooks
// 排序
// 传入 notebookId => Seq
// 为什么要传入userId, 防止修改其它用户的信息 (恶意)
// [ok]
func (this *NotebookService) SortNotebooks(userId string, notebookId2Seqs map[string]int) bool {
if len(notebookId2Seqs) == 0 {
return false
}
for notebookId, seq := range notebookId2Seqs {
if !db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"Seq": seq, "Usn": userService.IncrUsn(userId)}) {
return false
}
}
return true
}
开发者ID:intZz,项目名称:leanote,代码行数:17,代码来源:NotebookService.go
示例16: DragNotebooks
// 排序和设置父
func (this *NotebookService) DragNotebooks(userId string, curNotebookId string, parentNotebookId string, siblings []string) bool {
ok := false
// 如果没parentNotebookId, 则parentNotebookId设空
if parentNotebookId == "" {
ok = db.UpdateByIdAndUserIdMap(db.Notebooks, curNotebookId, userId, bson.M{"ParentNotebookId": "", "Usn": userService.IncrUsn(userId)})
} else {
ok = db.UpdateByIdAndUserIdMap(db.Notebooks, curNotebookId, userId, bson.M{"ParentNotebookId": bson.ObjectIdHex(parentNotebookId), "Usn": userService.IncrUsn(userId)})
}
if !ok {
return false
}
// 排序
for seq, notebookId := range siblings {
if !db.UpdateByIdAndUserIdMap(db.Notebooks, notebookId, userId, bson.M{"Seq": seq, "Usn": userService.IncrUsn(userId)}) {
return false
}
}
return true
}
开发者ID:intZz,项目名称:leanote,代码行数:23,代码来源:NotebookService.go
示例17: UpdateSingleUrlTitle
// 修改urlTitle
func (this *BlogService) UpdateSingleUrlTitle(userId, singleId, urlTitle string) (ok bool, url string) {
url = urlTitle
/*
// 先清空
ok = db.UpdateByIdAndUserIdMap(db.BlogSingles, singleId, userId, bson.M{
"UrlTitle": "",
})
*/
url = GetUrTitle(userId, urlTitle, "single", singleId)
ok = db.UpdateByIdAndUserIdMap(db.BlogSingles, singleId, userId, bson.M{
"UrlTitle": url,
})
if ok {
// 还要修改UserBlog中的Singles
this.updateBlogSingles(userId, false, false, singleId, "", url)
}
// 返回给前端的是decode
url = decodeValue(url)
return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:21,代码来源:BlogService.go
示例18: UpdateNoteContent
// 修改笔记本内容
// [ok] TODO perm未测
func (this *NoteService) UpdateNoteContent(userId, updatedUserId, noteId, content, abstract string) bool {
// updatedUserId 要修改userId的note, 此时需要判断是否有修改权限
if userId != updatedUserId {
if !shareService.HasUpdatePerm(userId, updatedUserId, noteId) {
Log("NO AUTH")
return false
}
}
if db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId,
bson.M{"UpdatedUserId": bson.ObjectIdHex(updatedUserId),
"Content": content,
"Abstract": abstract,
"UpdatedTime": time.Now()}) {
// 这里, 添加历史记录
noteContentHistoryService.AddHistory(noteId, userId, info.EachHistory{UpdatedUserId: bson.ObjectIdHex(updatedUserId),
Content: content,
UpdatedTime: time.Now(),
})
return true
}
return false
}
开发者ID:jianping11,项目名称:leanote,代码行数:26,代码来源:NoteService.go
示例19: UpdateNoteContentIsBlog
// 当设置/取消了笔记为博客
func (this *NoteService) UpdateNoteContentIsBlog(noteId, userId string, isBlog bool) {
db.UpdateByIdAndUserIdMap(db.NoteContents, noteId, userId, bson.M{"IsBlog": isBlog})
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:4,代码来源:NoteService.go
示例20: IncrNoteUsn
// 附件修改, 增加noteIncr
func (this *NoteService) IncrNoteUsn(noteId, userId string) int {
afterUsn := userService.IncrUsn(userId)
db.UpdateByIdAndUserIdMap(db.Notes, noteId, userId,
bson.M{"UpdatedTime": time.Now(), "Usn": afterUsn})
return afterUsn
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:7,代码来源:NoteService.go
注:本文中的github.com/leanote/leanote/app/db.UpdateByIdAndUserIdMap函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论