本文整理汇总了Golang中github.com/leanote/leanote/app/db.GetByIdAndUserId函数的典型用法代码示例。如果您正苦于以下问题:Golang GetByIdAndUserId函数的具体用法?Golang GetByIdAndUserId怎么用?Golang GetByIdAndUserId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetByIdAndUserId函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: DeleteImage
// delete image
func (this *FileService) DeleteImage(userId, fileId string) (bool, string) {
file := info.File{}
db.GetByIdAndUserId(db.Files, fileId, userId, &file)
if file.FileId != "" {
if db.DeleteByIdAndUserId(db.Files, fileId, userId) {
// delete image
// TODO
file.Path = strings.TrimLeft(file.Path, "/")
var err error
if strings.HasPrefix(file.Path, "upload") {
Log(file.Path)
err = os.Remove(revel.BasePath + "/public/" + file.Path)
} else {
err = os.Remove(revel.BasePath + "/" + file.Path)
}
if err == nil {
return true, ""
}
return false, "delete file error!"
}
return false, "db error"
}
return false, "no such item"
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:26,代码来源:FileService.go
示例2: AddHistory
// 新建一个note, 不需要添加历史记录
// 添加历史
func (this *NoteContentHistoryService) AddHistory(noteId, userId string, eachHistory info.EachHistory) {
// 检查是否是空
if eachHistory.Content == "" {
return
}
// 先查是否存在历史记录, 没有则添加之
history := info.NoteContentHistory{}
db.GetByIdAndUserId(db.NoteContentHistories, noteId, userId, &history)
if history.NoteId == "" {
this.newHistory(noteId, userId, eachHistory)
} else {
// 判断是否超出 maxSize, 如果超出则pop最后一个, 再push之, 不用那么麻烦, 直接update吧, 虽然影响性能
// TODO
l := len(history.Histories)
if l >= maxSize {
// history.Histories = history.Histories[l-maxSize:] // BUG, 致使都是以前的
history.Histories = history.Histories[:maxSize]
}
newHistory := []info.EachHistory{eachHistory}
newHistory = append(newHistory, history.Histories...) // 在开头加了, 最近的在最前
history.Histories = newHistory
// 更新之
db.UpdateByIdAndUserId(db.NoteContentHistories, noteId, userId, history)
}
return
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:30,代码来源:NoteContentHistoryService.go
示例3: CopyImage
// 复制共享的笔记时, 复制其中的图片到我本地
// 复制图片
func (this *FileService) CopyImage(userId, fileId, toUserId string) (bool, string) {
// 是否已经复制过了
file2 := info.File{}
db.GetByQ(db.Files, bson.M{"UserId": bson.ObjectIdHex(toUserId), "FromFileId": bson.ObjectIdHex(fileId)}, &file2)
if file2.FileId != "" {
return true, file2.FileId.Hex()
}
// 复制之
file := info.File{}
db.GetByIdAndUserId(db.Files, fileId, userId, &file)
if file.FileId == "" || file.UserId.Hex() != userId {
return false, ""
}
_, ext := SplitFilename(file.Name)
guid := NewGuid()
newFilename := guid + ext
// TODO 统一目录格式
// dir := "files/" + toUserId + "/images"
dir := "files/" + GetRandomFilePath(toUserId, guid) + "/images"
filePath := dir + "/" + newFilename
err := os.MkdirAll(revel.BasePath+dir, 0755)
if err != nil {
return false, ""
}
_, err = CopyFile(revel.BasePath+"/"+file.Path, revel.BasePath+"/"+filePath)
if err != nil {
return false, ""
}
fileInfo := info.File{Name: newFilename,
Title: file.Title,
Path: filePath,
Size: file.Size,
FromFileId: file.FileId}
id := bson.NewObjectId()
fileInfo.FileId = id
fileId = id.Hex()
Ok, _ := this.AddImage(fileInfo, "", toUserId, false)
if Ok {
return Ok, id.Hex()
}
return false, ""
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:51,代码来源:FileService.go
示例4: DeleteImage
// delete image
func (this *FileService) DeleteImage(userId, fileId string) (bool, string) {
file := info.File{}
db.GetByIdAndUserId(db.Files, fileId, userId, &file)
if file.FileId != "" {
if db.DeleteByIdAndUserId(db.Files, fileId, userId) {
// delete image
err := os.Remove(revel.BasePath + "/public/" + file.Path)
if err == nil {
return true, ""
}
return false, "delete file error!"
}
return false, "db error"
}
return false, "no such item"
}
开发者ID:kevinhuo88888,项目名称:leanote,代码行数:18,代码来源:FileService.go
示例5: GetNotebook
// 得到某notebook
func (this *NotebookService) GetNotebook(notebookId, userId string) info.Notebook {
notebook := info.Notebook{}
db.GetByIdAndUserId(db.Notebooks, notebookId, userId, ¬ebook)
return notebook
}
开发者ID:sunyinhuiCoding,项目名称:leanote,代码行数:6,代码来源:NotebookService.go
示例6: GetNoteContent
// 通过id, userId得到noteContent
func (this *NoteService) GetNoteContent(noteContentId, userId string) (noteContent info.NoteContent) {
noteContent = info.NoteContent{}
db.GetByIdAndUserId(db.NoteContents, noteContentId, userId, ¬eContent)
return
}
开发者ID:jianping11,项目名称:leanote,代码行数:6,代码来源:NoteService.go
示例7: GetNote
// 通过id, userId得到note
func (this *NoteService) GetNote(noteId, userId string) (note info.Note) {
note = info.Note{}
db.GetByIdAndUserId(db.Notes, noteId, userId, ¬e)
return
}
开发者ID:jianping11,项目名称:leanote,代码行数:6,代码来源:NoteService.go
示例8: GetGroup
// 得到分组, shareService用
func (this *GroupService) GetGroup(userId, groupId string) info.Group {
// 得到分组s
group := info.Group{}
db.GetByIdAndUserId(db.Groups, groupId, userId, &group)
return group
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:7,代码来源:GroupService.go
示例9: ListHistories
// 列表展示
func (this *NoteContentHistoryService) ListHistories(noteId, userId string) []info.EachHistory {
histories := info.NoteContentHistory{}
db.GetByIdAndUserId(db.NoteContentHistories, noteId, userId, &histories)
return histories.Histories
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:6,代码来源:NoteContentHistoryService.go
注:本文中的github.com/leanote/leanote/app/db.GetByIdAndUserId函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论