本文整理汇总了Golang中github.com/leanote/leanote/app/info.NewPage函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPage函数的具体用法?Golang NewPage怎么用?Golang NewPage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewPage函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: SearchBlogByTags
// 根据tag搜索博客
func (this *BlogService) SearchBlogByTags(tags []string, userId string, pageNumber, pageSize int, sortField string, isAsc bool) (pageInfo info.Page, blogs []info.BlogItem) {
notes := []info.Note{}
skipNum, sortFieldR := parsePageAndSort(pageNumber, pageSize, sortField, isAsc)
// 不是trash的
query := bson.M{"UserId": bson.ObjectIdHex(userId),
"IsTrash": false,
"IsDeleted": false,
"IsBlog": true,
"Tags": bson.M{"$all": tags}}
q := db.Notes.Find(query)
// 总记录数
count, _ := q.Count()
if count == 0 {
return
}
q.Sort(sortFieldR).
Skip(skipNum).
Limit(pageSize).
All(¬es)
blogs = this.notes2BlogItems(notes)
pageInfo = info.NewPage(pageNumber, pageSize, count, nil)
return
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:30,代码来源:BlogService.go
示例2: SearchBlog
func (this *BlogService) SearchBlog(key, userId string, page, pageSize int, sortField string, isAsc bool) (info.Page, []info.BlogItem) {
count, notes := noteService.SearchNote(key, userId, page, pageSize, sortField, isAsc, true)
if notes == nil || len(notes) == 0 {
return info.Page{}, nil
}
blogs := this.notes2BlogItems(notes)
pageInfo := info.NewPage(page, pageSize, count, nil)
return pageInfo, blogs
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:11,代码来源:BlogService.go
示例3: ListComments
// 评论列表
// userId主要是显示userId是否点过某评论的赞
// 还要获取用户信息
func (this *BlogService) ListComments(userId, noteId string, page, pageSize int) (info.Page, []info.BlogCommentPublic, map[string]info.UserAndBlog) {
pageInfo := info.Page{CurPage: page}
comments2 := []info.BlogComment{}
skipNum, sortFieldR := parsePageAndSort(page, pageSize, "CreatedTime", false)
query := bson.M{"NoteId": bson.ObjectIdHex(noteId)}
q := db.BlogComments.Find(query)
// 总记录数
count, _ := q.Count()
q.Sort(sortFieldR).Skip(skipNum).Limit(pageSize).All(&comments2)
if len(comments2) == 0 {
return pageInfo, nil, nil
}
comments := make([]info.BlogCommentPublic, len(comments2))
// 我是否点过赞呢?
for i, comment := range comments2 {
comments[i].BlogComment = comment
if comment.LikeNum > 0 && comment.LikeUserIds != nil && len(comment.LikeUserIds) > 0 && InArray(comment.LikeUserIds, userId) {
comments[i].IsILikeIt = true
}
}
note := noteService.GetNoteById(noteId)
// 得到用户信息
userIdsMap := map[bson.ObjectId]bool{note.UserId: true}
for _, comment := range comments {
userIdsMap[comment.UserId] = true
if comment.ToUserId != "" { // 可能为空
userIdsMap[comment.ToUserId] = true
}
}
userIds := make([]bson.ObjectId, len(userIdsMap))
i := 0
for userId, _ := range userIdsMap {
userIds[i] = userId
i++
}
// 得到用户信息
userMap := userService.MapUserAndBlogByUserIds(userIds)
pageInfo = info.NewPage(page, pageSize, count, nil)
return pageInfo, comments, userMap
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:53,代码来源:BlogService.go
示例4: ListEmailLogs
func (this *EmailService) ListEmailLogs(pageNumber, pageSize int, sortField string, isAsc bool, email string) (page info.Page, emailLogs []info.EmailLog) {
emailLogs = []info.EmailLog{}
skipNum, sortFieldR := parsePageAndSort(pageNumber, pageSize, sortField, isAsc)
query := bson.M{}
if email != "" {
query["Email"] = bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}}
}
q := db.EmailLogs.Find(query)
// 总记录数
count, _ := q.Count()
// 列表
q.Sort(sortFieldR).
Skip(skipNum).
Limit(pageSize).
All(&emailLogs)
page = info.NewPage(pageNumber, pageSize, count, nil)
return
}
开发者ID:ClaudeXin,项目名称:leanote,代码行数:18,代码来源:EmailService.go
示例5: ListBlogs
// 博客列表
// userId 表示谁的blog
func (this *BlogService) ListBlogs(userId, notebookId string, page, pageSize int, sortField string, isAsc bool) (info.Page, []info.BlogItem) {
count, notes := noteService.ListNotes(userId, notebookId, false, page, pageSize, sortField, isAsc, true)
if notes == nil || len(notes) == 0 {
return info.Page{}, nil
}
// 得到content, 并且每个都要substring
noteIds := make([]bson.ObjectId, len(notes))
for i, note := range notes {
noteIds[i] = note.NoteId
}
// 直接得到noteContents表的abstract
// 这里可能是乱序的
noteContents := noteService.ListNoteAbstractsByNoteIds(noteIds) // 返回[info.NoteContent]
noteContentsMap := make(map[bson.ObjectId]info.NoteContent, len(noteContents))
for _, noteContent := range noteContents {
noteContentsMap[noteContent.NoteId] = noteContent
}
// 组装成blogItem
// 按照notes的顺序
blogs := make([]info.BlogItem, len(noteIds))
for i, note := range notes {
hasMore := true
var content string
var abstract string
if noteContent, ok := noteContentsMap[note.NoteId]; ok {
abstract = noteContent.Abstract
content = noteContent.Content
}
blogs[i] = info.BlogItem{note, abstract, content, hasMore, info.User{}}
}
pageInfo := info.NewPage(page, pageSize, count, nil)
return pageInfo, blogs
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:41,代码来源:BlogService.go
示例6: ListUsers
//-------------
// user admin
func (this *UserService) ListUsers(pageNumber, pageSize int, sortField string, isAsc bool, email string) (page info.Page, users []info.User) {
users = []info.User{}
skipNum, sortFieldR := parsePageAndSort(pageNumber, pageSize, sortField, isAsc)
query := bson.M{}
if email != "" {
orQ := []bson.M{
bson.M{"Email": bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}}},
bson.M{"Username": bson.M{"$regex": bson.RegEx{".*?" + email + ".*", "i"}}},
}
query["$or"] = orQ
}
q := db.Users.Find(query)
// 总记录数
count, _ := q.Count()
// 列表
q.Sort(sortFieldR).
Skip(skipNum).
Limit(pageSize).
All(&users)
page = info.NewPage(pageNumber, pageSize, count, nil)
return
}
开发者ID:rainkong,项目名称:leanote,代码行数:24,代码来源:UserService.go
示例7: ListAllBlogs
//-------
// p
// 平台 lea+
// 博客列表
func (this *BlogService) ListAllBlogs(userId, tag string, keywords string, isRecommend bool, page, pageSize int, sorterField string, isAsc bool) (info.Page, []info.BlogItem) {
pageInfo := info.Page{CurPage: page}
notes := []info.Note{}
skipNum, sortFieldR := parsePageAndSort(page, pageSize, sorterField, isAsc)
// 不是trash的
query := bson.M{"IsTrash": false, "IsDeleted": false, "IsBlog": true, "Title": bson.M{"$ne": "欢迎来到leanote!"}}
if tag != "" {
query["Tags"] = bson.M{"$in": []string{tag}}
}
if userId != "" {
query["UserId"] = bson.ObjectIdHex(userId)
}
// 不是demo的博客
demoUserId := configService.GetGlobalStringConfig("demoUserId")
if userId == "" && demoUserId != "" {
query["UserId"] = bson.M{"$ne": bson.ObjectIdHex(demoUserId)}
}
if isRecommend {
query["IsRecommend"] = isRecommend
}
if keywords != "" {
query["Title"] = bson.M{"$regex": bson.RegEx{".*?" + keywords + ".*", "i"}}
}
q := db.Notes.Find(query)
// 总记录数
count, _ := q.Count()
q.Sort(sortFieldR).
Skip(skipNum).
Limit(pageSize).
All(¬es)
if notes == nil || len(notes) == 0 {
return pageInfo, nil
}
// 得到content, 并且每个都要substring
noteIds := make([]bson.ObjectId, len(notes))
userIds := make([]bson.ObjectId, len(notes))
for i, note := range notes {
noteIds[i] = note.NoteId
userIds[i] = note.UserId
}
// 可以不要的
// 直接得到noteContents表的abstract
// 这里可能是乱序的
/*
noteContents := noteService.ListNoteAbstractsByNoteIds(noteIds) // 返回[info.NoteContent]
noteContentsMap := make(map[bson.ObjectId]info.NoteContent, len(noteContents))
for _, noteContent := range noteContents {
noteContentsMap[noteContent.NoteId] = noteContent
}
*/
// 得到用户信息
userMap := userService.MapUserInfoAndBlogInfosByUserIds(userIds)
// 组装成blogItem
// 按照notes的顺序
blogs := make([]info.BlogItem, len(noteIds))
for i, note := range notes {
hasMore := true
var content string
/*
if noteContent, ok := noteContentsMap[note.NoteId]; ok {
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)
return pageInfo, blogs
}
开发者ID:ZypcGroup,项目名称:leanote,代码行数:86,代码来源:BlogService.go
注:本文中的github.com/leanote/leanote/app/info.NewPage函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论