feat: update player
This commit is contained in:
@@ -186,19 +186,24 @@ func (m *usersModel) DeleteByID(ctx context.Context, id int64) error {
|
||||
}
|
||||
|
||||
// PostList returns a paginated list of posts for a user
|
||||
func (m *usersModel) PostList(ctx context.Context, userId int64, pagination *requests.Pagination, keyword *string, callbacks ...func(model.Posts) model.Posts) (*requests.Pager, error) {
|
||||
func (m *usersModel) PostList(ctx context.Context, userId int64, pagination *requests.Pagination, cond BoolExpression, callbacks ...func(model.Posts) model.Posts) (*requests.Pager, error) {
|
||||
pagination.Format()
|
||||
|
||||
tblUserPosts := table.UserPosts
|
||||
|
||||
cond = cond.AND(
|
||||
tblUserPosts.UserID.EQ(Int64(userId)),
|
||||
)
|
||||
|
||||
tbl := table.Posts
|
||||
stmt := SELECT(tbl.AllColumns).
|
||||
FROM(tbl.
|
||||
INNER_JOIN(
|
||||
RIGHT_JOIN(
|
||||
tblUserPosts,
|
||||
tblUserPosts.PostID.EQ(tbl.ID).
|
||||
AND(tblUserPosts.UserID.EQ(Int64(userId)))),
|
||||
tblUserPosts.PostID.EQ(tbl.ID),
|
||||
),
|
||||
).
|
||||
WHERE(cond).
|
||||
ORDER_BY(tblUserPosts.ID.DESC()).
|
||||
LIMIT(pagination.Limit).
|
||||
OFFSET(pagination.Offset)
|
||||
@@ -207,6 +212,13 @@ func (m *usersModel) PostList(ctx context.Context, userId int64, pagination *req
|
||||
var posts []model.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user