This commit is contained in:
@@ -257,7 +257,11 @@ func (ctl *posts) Mine(
|
||||
|
||||
conds := []gen.Condition{
|
||||
models.PostQuery.Status.Eq(fields.PostStatusPublished),
|
||||
models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)),
|
||||
}
|
||||
if query.Keyword != nil && *query.Keyword != "" {
|
||||
conds = append(conds,
|
||||
models.PostQuery.Title.Like(database.WrapLike(*query.Keyword)),
|
||||
)
|
||||
}
|
||||
|
||||
pager, err := services.Users.PostList(ctx, user.ID, pagination, conds...)
|
||||
|
||||
@@ -56,39 +56,26 @@ func (m *users) PostList(
|
||||
// OFFSET(pagination.Offset)
|
||||
// m.log().Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
// var posts []Posts
|
||||
// err := stmt.QueryContext(ctx, db, &posts)
|
||||
// if err != nil {
|
||||
// if errors.Is(err, qrm.ErrNoRows) {
|
||||
// return &requests.Pager{
|
||||
// Items: nil,
|
||||
// Total: 0,
|
||||
// Pagination: *pagination,
|
||||
// }, nil
|
||||
// }
|
||||
// m.log().Errorf("error querying posts: %v", err)
|
||||
// return nil, err
|
||||
// }
|
||||
tbl, query := models.UserPostQuery.QueryContext(ctx)
|
||||
pagePosts, cnt, err := query.Select(tbl.PostID).
|
||||
Where(tbl.UserID.Eq(userId)).
|
||||
FindByPage(int(pagination.Offset()), int(pagination.Limit))
|
||||
|
||||
// // total count
|
||||
// var cnt struct {
|
||||
// Cnt int64
|
||||
// }
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
postIds := lo.Map(pagePosts, func(item *models.UserPost, _ int) int64 { return item.PostID })
|
||||
|
||||
// stmtCnt := tblUserPosts.SELECT(COUNT(tblUserPosts.ID).AS("cnt")).WHERE(tblUserPosts.UserID.EQ(Int64(userId)))
|
||||
// m.log().Infof("sql: %s", stmtCnt.DebugSql())
|
||||
|
||||
// if err := stmtCnt.QueryContext(ctx, db, &cnt); err != nil {
|
||||
// m.log().Errorf("error counting users: %v", err)
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// return &requests.Pager{
|
||||
// Items: posts,
|
||||
// Total: cnt.Cnt,
|
||||
// Pagination: *pagination,
|
||||
// }, nil
|
||||
return nil, nil
|
||||
postTbl, postQuery := models.PostQuery.QueryContext(ctx)
|
||||
items, err := postQuery.Where(postTbl.ID.In(postIds...)).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &requests.Pager{
|
||||
Items: items,
|
||||
Total: cnt,
|
||||
Pagination: *pagination,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetUsersMapByIDs
|
||||
|
||||
Reference in New Issue
Block a user