|
|
|
@ -54,7 +54,7 @@ func NewFriendMongo(db *mongo.Database) (database.Friend, error) {
|
|
|
|
|
|
|
|
|
|
// Create inserts multiple friend records.
|
|
|
|
|
func (f *FriendMgo) Create(ctx context.Context, friends []*model.Friend) error {
|
|
|
|
|
return IncrVersion(func() error {
|
|
|
|
|
return mongoutil.IncrVersion(func() error {
|
|
|
|
|
return mongoutil.InsertMany(ctx, f.coll, friends)
|
|
|
|
|
}, func() error {
|
|
|
|
|
mp := make(map[string][]string)
|
|
|
|
@ -76,7 +76,7 @@ func (f *FriendMgo) Delete(ctx context.Context, ownerUserID string, friendUserID
|
|
|
|
|
"owner_user_id": ownerUserID,
|
|
|
|
|
"friend_user_id": bson.M{"$in": friendUserIDs},
|
|
|
|
|
}
|
|
|
|
|
return IncrVersion(func() error {
|
|
|
|
|
return mongoutil.IncrVersion(func() error {
|
|
|
|
|
return mongoutil.DeleteOne(ctx, f.coll, filter)
|
|
|
|
|
}, func() error {
|
|
|
|
|
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, true)
|
|
|
|
@ -92,7 +92,7 @@ func (f *FriendMgo) UpdateByMap(ctx context.Context, ownerUserID string, friendU
|
|
|
|
|
"owner_user_id": ownerUserID,
|
|
|
|
|
"friend_user_id": friendUserID,
|
|
|
|
|
}
|
|
|
|
|
return IncrVersion(func() error {
|
|
|
|
|
return mongoutil.IncrVersion(func() error {
|
|
|
|
|
return mongoutil.UpdateOne(ctx, f.coll, filter, bson.M{"$set": args}, true)
|
|
|
|
|
}, func() error {
|
|
|
|
|
return f.owner.WriteLog(ctx, ownerUserID, []string{friendUserID}, false)
|
|
|
|
@ -152,13 +152,6 @@ func (f *FriendMgo) FindOwnerFriends(ctx context.Context, ownerUserID string, pa
|
|
|
|
|
func (f *FriendMgo) FindOwnerFriendUserIds(ctx context.Context, ownerUserID string, limit int) ([]string, error) {
|
|
|
|
|
filter := bson.M{"owner_user_id": ownerUserID}
|
|
|
|
|
opt := options.Find().SetProjection(bson.M{"_id": 0, "friend_user_id": 1}).SetSort(bson.D{{"friend_nickname", 1}, {"create_time", 1}}).SetLimit(int64(limit))
|
|
|
|
|
//res, err := mongoutil.Find[string](ctx, f.coll, filter, opt)
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// errMsg := err.Error()
|
|
|
|
|
// _ = errMsg
|
|
|
|
|
// return nil, err
|
|
|
|
|
//}
|
|
|
|
|
//return res, nil
|
|
|
|
|
return mongoutil.Find[string](ctx, f.coll, filter, opt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -189,7 +182,7 @@ func (f *FriendMgo) UpdateFriends(ctx context.Context, ownerUserID string, frien
|
|
|
|
|
// Create an update document
|
|
|
|
|
update := bson.M{"$set": val}
|
|
|
|
|
|
|
|
|
|
return IncrVersion(func() error {
|
|
|
|
|
return mongoutil.IncrVersion(func() error {
|
|
|
|
|
return mongoutil.Ignore(mongoutil.UpdateMany(ctx, f.coll, filter, update))
|
|
|
|
|
}, func() error {
|
|
|
|
|
return f.owner.WriteLog(ctx, ownerUserID, friendUserIDs, false)
|
|
|
|
@ -227,12 +220,3 @@ func (f *FriendMgo) SearchFriend(ctx context.Context, ownerUserID, keyword strin
|
|
|
|
|
//return f.aggregatePagination(ctx, where, pagination)
|
|
|
|
|
panic("todo")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func IncrVersion(dbs ...func() error) error {
|
|
|
|
|
for _, fn := range dbs {
|
|
|
|
|
if err := fn(); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|