feat: update order s
This commit is contained in:
@@ -343,3 +343,30 @@ func (m *postsModel) Bought(ctx context.Context, userId int64, pagination *reque
|
||||
Pagination: *pagination,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetPostsMapByIDs
|
||||
func (m *postsModel) GetPostsMapByIDs(ctx context.Context, ids []int64) (map[int64]model.Posts, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
tbl := table.Posts
|
||||
stmt := tbl.
|
||||
SELECT(tbl.AllColumns).
|
||||
WHERE(
|
||||
tbl.ID.IN(lo.Map(ids, func(id int64, _ int) Expression { return Int64(id) })...),
|
||||
)
|
||||
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var posts []model.Posts = make([]model.Posts, 0)
|
||||
err := stmt.QueryContext(ctx, db, &posts)
|
||||
if err != nil {
|
||||
m.log.Errorf("error querying posts: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return lo.SliceToMap(posts, func(item model.Posts) (int64, model.Posts) {
|
||||
return item.ID, item
|
||||
}), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user