feat: add bought check
This commit is contained in:
@@ -322,6 +322,29 @@ func (m *usersModel) GetUsersMapByIDs(ctx context.Context, ids []int64) (map[int
|
||||
}), nil
|
||||
}
|
||||
|
||||
func (m *usersModel) BatchCheckHasBought(ctx context.Context, userID int64, postIDs []int64) (map[int64]bool, error) {
|
||||
tbl := table.UserPosts
|
||||
stmt := tbl.SELECT(tbl.PostID.AS("post_id")).WHERE(
|
||||
tbl.UserID.EQ(Int64(userID)).AND(
|
||||
tbl.PostID.IN(lo.Map(postIDs, func(id int64, _ int) Expression { return Int64(id) })...),
|
||||
),
|
||||
)
|
||||
|
||||
var userPosts []struct {
|
||||
PostID int64
|
||||
}
|
||||
if err := stmt.QueryContext(ctx, db, &userPosts); err != nil {
|
||||
m.log.Errorf("error querying user posts: %v", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := make(map[int64]bool)
|
||||
for _, post := range userPosts {
|
||||
result[post.PostID] = true
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// HasBought
|
||||
func (m *usersModel) HasBought(ctx context.Context, userID, postID int64) (bool, error) {
|
||||
tbl := table.UserPosts
|
||||
|
||||
Reference in New Issue
Block a user