diff --git a/app/service/BlogService.go b/app/service/BlogService.go index 82cc374..dc94156 100644 --- a/app/service/BlogService.go +++ b/app/service/BlogService.go @@ -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}, ¬e) + db.GetByQ(db.Notes, bson.M{"UserId": bson.ObjectIdHex(userId), "UrlTitle": encodeValue(noteIdOrUrlTitle), + "IsBlog": true, + "IsTrash": false, "IsDeleted": false}, ¬e) 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"}, ¬es) 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) } @@ -291,9 +293,10 @@ func (this *BlogService) SearchBlogByTags(tags []string, userId string, pageNumb // 不是trash的 query := bson.M{"UserId": bson.ObjectIdHex(userId), - "IsTrash": false, - "IsBlog": true, - "Tags": bson.M{"$all": tags}} + "IsTrash": false, + "IsDeleted": false, + "IsBlog": true, + "Tags": bson.M{"$all": tags}} q := db.Notes.Find(query) @@ -366,10 +369,10 @@ func (this *BlogService) PreNextBlog(userId string, sorterField string, isAsc bo if !isAsc { // 降序 /* - ------- pre - ----- now - --- next - -- + ------- pre + ----- now + --- next + -- */ // 上一篇时间要比它大, 找最小的 sortFieldT1 = bson.M{"$gte": baseTime} // 为什么要相等, 因为将notebook发布成博客, 会统一修改note的publicTime, 此时所有notes都一样 @@ -393,12 +396,14 @@ func (this *BlogService) PreNextBlog(userId string, sorterField string, isAsc bo sortFieldR2 = sorterField } + // 1 // 上一篇, 比基时间要小, 但是是最后一篇, 所以是降序 note := info.Note{} - query := bson.M{"UserId": userIdO, - "IsTrash": false, - "IsBlog": true, - "_id": bson.M{"$ne": bson.ObjectIdHex(noteId)}, + query := bson.M{"UserId": userIdO, + "IsTrash": false, + "IsDeleted": false, + "IsBlog": true, + "_id": bson.M{"$ne": bson.ObjectIdHex(noteId)}, sorterField: sortFieldT1, } q := db.Notes.Find(query) @@ -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) diff --git a/app/service/NoteService.go b/app/service/NoteService.go index 3bb6293..b87ab1d 100644 --- a/app/service/NoteService.go +++ b/app/service/NoteService.go @@ -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}, ¬e) + db.GetByQ(db.Notes, bson.M{"_id": bson.ObjectIdHex(noteId), + "IsBlog": true, "IsTrash": false, "IsDeleted": false}, ¬e) 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) }