fix: update issues
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/go-jet/jet/v2/qrm"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -120,7 +121,7 @@ func (m *postsModel) countByCondition(ctx context.Context, expr BoolExpression)
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
func (m *postsModel) List(ctx context.Context, pagination *requests.Pagination, cond BoolExpression) (*requests.Pager, error) {
|
||||
func (m *postsModel) List(ctx context.Context, pagination *requests.Pagination, cond BoolExpression, callbacks ...func(model.Posts) model.Posts) (*requests.Pager, error) {
|
||||
pagination.Format()
|
||||
|
||||
tbl := table.Posts
|
||||
@@ -145,6 +146,14 @@ func (m *postsModel) List(ctx context.Context, pagination *requests.Pagination,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(callbacks) > 0 {
|
||||
for _, f := range callbacks {
|
||||
posts = lo.Map(posts, func(item model.Posts, _ int) model.Posts {
|
||||
return f(item)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &requests.Pager{
|
||||
Items: posts,
|
||||
Total: count,
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"quyun/database/schemas/public/table"
|
||||
|
||||
. "github.com/go-jet/jet/v2/postgres"
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -183,7 +184,7 @@ 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) (*requests.Pager, error) {
|
||||
func (m *usersModel) PostList(ctx context.Context, userId int64, pagination *requests.Pagination, keyword *string, callbacks ...func(model.Posts) model.Posts) (*requests.Pager, error) {
|
||||
pagination.Format()
|
||||
|
||||
tblUserPosts := table.UserPosts
|
||||
@@ -221,6 +222,14 @@ func (m *usersModel) PostList(ctx context.Context, userId int64, pagination *req
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(callbacks) > 0 {
|
||||
for _, f := range callbacks {
|
||||
posts = lo.Map(posts, func(item model.Posts, _ int) model.Posts {
|
||||
return f(item)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &requests.Pager{
|
||||
Items: posts,
|
||||
Total: cnt.Cnt,
|
||||
|
||||
Reference in New Issue
Block a user