Пример #1
0
// 删除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
}
Пример #2
0
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
}
Пример #3
0
// 删除trash
func (this *TrashService) DeleteTrash(noteId, userId string) bool {
	// delete note's attachs
	ok := attachService.DeleteAllAttachs(noteId, userId)

	// delete note
	ok = db.DeleteByIdAndUserId(db.Notes, noteId, userId)
	// delete content
	ok = db.DeleteByIdAndUserId(db.NoteContents, noteId, userId)

	return ok
}
Пример #4
0
// 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"
}
Пример #5
0
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
}
Пример #6
0
// 删除页面
func (this *BlogService) DeleteSingle(userId, singleId string) (ok bool) {
	ok = db.DeleteByIdAndUserId(db.BlogSingles, singleId, userId)
	if ok {
		// 还要修改UserBlog中的Singles
		this.updateBlogSingles(userId, true, false, singleId, "", "")
	}
	return
}
Пример #7
0
// delete album
// presupposition: has no images under this ablum
func (this *AlbumService) DeleteAlbum(userId, albumId string) (bool, string) {
	if db.Count(db.Files, bson.M{"AlbumId": bson.ObjectIdHex(albumId),
		"UserId": bson.ObjectIdHex(userId),
	}) == 0 {
		return db.DeleteByIdAndUserId(db.Albums, albumId, userId), ""
	}
	return false, "has images"
}
Пример #8
0
// 先查看该notebookId下是否有notes, 没有则删除
func (this *NotebookService) DeleteNotebook(userId, notebookId string) (bool, string) {
	if db.Count(db.Notes, bson.M{"NotebookId": bson.ObjectIdHex(notebookId),
		"UserId":  bson.ObjectIdHex(userId),
		"IsTrash": false}) == 0 { // 不包含trash
		return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
	}
	return false, "笔记本下有笔记"
}
Пример #9
0
// API调用, 删除笔记本, 不作笔记控制
func (this *NotebookService) DeleteNotebookForce(userId, notebookId string, usn int) (bool, string) {
	notebook := this.GetNotebookById(notebookId)
	// 不存在
	if notebook.NotebookId == "" {
		return false, "notExists"
	} else if notebook.Usn != usn {
		return false, "conflict"
	}
	return db.DeleteByIdAndUserId(db.Notebooks, notebookId, userId), ""
}
Пример #10
0
// 删除分组
// 判断是否有好友
func (this *GroupService) DeleteGroup(userId, groupId string) (ok bool, msg string) {
	/*
		if db.Has(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId)}) {
			return false, "groupHasUsers"
		}
	*/
	db.DeleteAll(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId)})
	return db.DeleteByIdAndUserId(db.Groups, groupId, userId), ""

	// TODO 删除分组后, 在shareNote, shareNotebook中也要删除
}
Пример #11
0
// 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"
}
Пример #12
0
// 删除分组
// 判断是否有好友
func (this *GroupService) DeleteGroup(userId, groupId string) (ok bool, msg string) {
	/*
		if db.Has(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId)}) {
			return false, "groupHasUsers"
		}
	*/
	if !this.isMyGroup(userId, groupId) {
		return false, "notMyGroup"
	}

	// 删除分组后, 需要删除所有用户分享到该组的笔记本, 笔记

	shareService.DeleteAllShareNotebookGroup(groupId)
	shareService.DeleteAllShareNoteGroup(groupId)

	db.DeleteAll(db.GroupUsers, bson.M{"GroupId": bson.ObjectIdHex(groupId)})
	return db.DeleteByIdAndUserId(db.Groups, groupId, userId), ""

	// TODO 删除分组后, 在shareNote, shareNotebook中也要删除
}
Пример #13
0
// 删除trash
func (this *TrashService) DeleteTrash(noteId, userId string) bool {
	return db.DeleteByIdAndUserId(db.Notes, noteId, userId)
}