feat: update order s

This commit is contained in:
yanghao05
2025-04-18 22:55:37 +08:00
parent 6ca359ec1e
commit 75bbca00cf
4 changed files with 111 additions and 16 deletions

View File

@@ -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
}