已删除的笔记还显示 #226

This commit is contained in:
lealife
2015-10-10 14:28:53 +08:00
parent da7d31fa00
commit db4cfbf605
2 changed files with 29 additions and 19 deletions

View File

@ -45,7 +45,9 @@ func (this *BlogService) GetBlogByIdAndUrlTitle(userId string, noteIdOrUrlTitle
return this.GetBlog(noteIdOrUrlTitle)
}
note := info.Note{}
db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle), "IsBlog": true, "IsTrash": false}, &note)
db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle),
"IsBlog": true,
"IsTrash": false, "IsDeleted": false}, &note)
return this.GetBlogItem(note)
}
@ -56,7 +58,7 @@ func (this *BlogService) GetBlog(noteId string) (blog info.BlogItem) {
}
func (this *BlogService) GetBlogItem(note info.Note) (blog info.BlogItem) {
if note.NoteId == "" || !note.IsBlog {
return
return info.BlogItem{}
}
// 内容
@ -142,7 +144,7 @@ func (this *BlogService) ReCountBlogTags(userId string) bool {
// 得到所有博客
notes := []info.Note{}
userIdO := bson.ObjectIdHex(userId)
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsBlog": true}
query := bson.M{"UserId": userIdO, "IsTrash": false, "IsDeleted": false, "IsBlog": true}
db.ListByQWithFields(db.Notes, query, []string{"Tags"}, &notes)
db.DeleteAll(db.TagCounts, bson.M{"UserId": userIdO, "IsBlog": true})
@ -184,7 +186,7 @@ Posts: []
*/
func (this *BlogService) ListBlogsArchive(userId, notebookId string, year, month int, sortField string, isAsc bool) []info.Archive {
// _, notes := noteService.ListNotes(userId, notebookId, false, 1, 99999, sortField, isAsc, true);
q := bson.M{"UserId": bson.ObjectIdHex(userId), "IsBlog": true, "IsTrash": false}
q := bson.M{"UserId": bson.ObjectIdHex(userId), "IsBlog": true, "IsTrash": false, "IsDeleted": false}
if notebookId != "" {
q["NotebookId"] = bson.ObjectIdHex(notebookId)
}
@ -292,6 +294,7 @@ func (this *BlogService) SearchBlogByTags(tags []string, userId string, pageNumb
// 不是trash的
query := bson.M{"UserId": bson.ObjectIdHex(userId),
"IsTrash": false,
"IsDeleted": false,
"IsBlog": true,
"Tags": bson.M{"$all": tags}}
@ -393,10 +396,12 @@ func (this *BlogService) PreNextBlog(userId string, sorterField string, isAsc bo
sortFieldR2 = sorterField
}
// 1
// 上一篇, 比基时间要小, 但是是最后一篇, 所以是降序
note := info.Note{}
query := bson.M{"UserId": userIdO,
"IsTrash": false,
"IsDeleted": false,
"IsBlog": true,
"_id": bson.M{"$ne": bson.ObjectIdHex(noteId)},
sorterField: sortFieldT1,
@ -430,7 +435,7 @@ func (this *BlogService) ListAllBlogs(userId, tag string, keywords string, isRec
skipNum, sortFieldR := parsePageAndSort(page, pageSize, sorterField, isAsc)
// 不是trash的
query := bson.M{"IsTrash": false, "IsBlog": true, "Title": bson.M{"$ne": "欢迎来到leanote!"}}
query := bson.M{"IsTrash": false, "IsDeleted": false, "IsBlog": true, "Title": bson.M{"$ne": "欢迎来到leanote!"}}
if tag != "" {
query["Tags"] = bson.M{"$in": []string{tag}}
}
@ -496,6 +501,9 @@ func (this *BlogService) ListAllBlogs(userId, tag string, keywords string, isRec
content = noteContent.Abstract
}
*/
if len(note.Tags) == 1 && note.Tags[0] == "" {
note.Tags = nil
}
blogs[i] = info.BlogItem{note, "", content, hasMore, userMap[note.UserId]}
}
pageInfo = info.NewPage(page, pageSize, count, nil)

View File

@ -28,7 +28,8 @@ func (this *NoteService) GetNoteById(noteId string) (note info.Note) {
// 不要传userId, 因为是公开的
func (this *NoteService) GetBlogNote(noteId string) (note info.Note) {
note = info.Note{}
db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId), "IsBlog": true, "IsTrash": false}, &note)
db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId),
"IsBlog": true, "IsTrash": false, "IsDeleted": false}, &note)
return
}
// 通过id, userId得到noteContent
@ -734,6 +735,7 @@ func (this *NoteService) SearchNote(key, userId string, pageNumber, pageSize int
// 不是trash的
query := bson.M{"UserId": bson.ObjectIdHex(userId),
"IsTrash": false,
"IsDeleted": false, // 不能搜索已删除了的
"$or": orQ,
}
if isBlog {
@ -819,14 +821,14 @@ func (this *NoteService) SearchNoteByTags(tags []string, userId string, pageNumb
//------------
// 统计
func (this *NoteService) CountNote(userId string) int {
q := bson.M{"IsTrash": false}
q := bson.M{"IsTrash": false, "IsDeleted": false}
if userId != "" {
q["UserId"] = bson.ObjectIdHex(userId)
}
return db.Count(db.Notes, q)
}
func (this *NoteService) CountBlog(userId string) int {
q := bson.M{"IsBlog": true, "IsTrash": false}
q := bson.M{"IsBlog": true, "IsTrash": false, "IsDeleted": false}
if userId != "" {
q["UserId"] = bson.ObjectIdHex(userId)
}