當前位置: 首頁>>代碼示例>>Golang>>正文


Golang db.UpdateByIdAndUserIdMap函數代碼示例

本文整理匯總了Golang中github.com/leanote/leanote/app/db.UpdateByIdAndUserIdMap函數的典型用法代碼示例。如果您正苦於以下問題:Golang UpdateByIdAndUserIdMap函數的具體用法?Golang UpdateByIdAndUserIdMap怎麽用?Golang UpdateByIdAndUserIdMap使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了UpdateByIdAndUserIdMap函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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"}, &notes)
	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"}, &notes)
			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


注:本文中的github.com/leanote/leanote/app/db.UpdateByIdAndUserIdMap函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。