fix: create time sort

pull/2090/head
Xinwei Xiong (cubxxw) 2 years ago
parent e86d1cd742
commit f7ede4cce1

@ -16,9 +16,10 @@ package mgo
import ( import (
"context" "context"
"github.com/OpenIMSDK/protocol/constant"
"time" "time"
"github.com/OpenIMSDK/protocol/constant"
"github.com/OpenIMSDK/tools/errs" "github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/mgoutil" "github.com/OpenIMSDK/tools/mgoutil"
"github.com/OpenIMSDK/tools/pagination" "github.com/OpenIMSDK/tools/pagination"
@ -70,8 +71,12 @@ func (g *GroupMgo) Take(ctx context.Context, groupID string) (group *relation.Gr
} }
func (g *GroupMgo) Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*relation.GroupModel, err error) { func (g *GroupMgo) Search(ctx context.Context, keyword string, pagination pagination.Pagination) (total int64, groups []*relation.GroupModel, err error) {
return mgoutil.FindPage[*relation.GroupModel](ctx, g.coll, bson.M{"group_name": bson.M{"$regex": keyword}, opts := options.Find().SetSort(bson.D{{Key: "created_at", Value: -1}})
"status": bson.M{"$ne": constant.GroupStatusDismissed}}, pagination)
return mgoutil.FindPage[*relation.GroupModel](ctx, g.coll, bson.M{
"group_name": bson.M{"$regex": keyword},
"status": bson.M{"$ne": constant.GroupStatusDismissed},
}, pagination, opts)
} }
func (g *GroupMgo) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) { func (g *GroupMgo) CountTotal(ctx context.Context, before *time.Time) (count int64, err error) {

Loading…
Cancel
Save