From 7834c038a9b5848a60e24d9e3d95b52d504aaab6 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Wed, 22 Nov 2023 14:38:56 +0800 Subject: [PATCH] friend --- pkg/common/db/newmgo/friend_request.go | 23 ++++++------------- .../db/table/relation/friend_request.go | 2 -- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/pkg/common/db/newmgo/friend_request.go b/pkg/common/db/newmgo/friend_request.go index b2525cf37..e7a45ecb4 100644 --- a/pkg/common/db/newmgo/friend_request.go +++ b/pkg/common/db/newmgo/friend_request.go @@ -21,28 +21,19 @@ type FriendRequestMgo struct { } func (f *FriendRequestMgo) FindToUserID(ctx context.Context, toUserID string, pagination pagination.Pagination) (total int64, friendRequests []*relation.FriendRequestModel, err error) { - //TODO implement me - panic("implement me") + return mgotool.FindPage[*relation.FriendRequestModel](ctx, f.coll, bson.M{"to_user_id": toUserID}, pagination) } func (f *FriendRequestMgo) FindFromUserID(ctx context.Context, fromUserID string, pagination pagination.Pagination) (total int64, friendRequests []*relation.FriendRequestModel, err error) { - //TODO implement me - panic("implement me") + return mgotool.FindPage[*relation.FriendRequestModel](ctx, f.coll, bson.M{"from_user_id": fromUserID}, pagination) } func (f *FriendRequestMgo) FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*relation.FriendRequestModel, err error) { - //TODO implement me - panic("implement me") -} - -func (f *FriendRequestMgo) NewTx(tx any) relation.FriendRequestModelInterface { - //TODO implement me - panic("implement me") -} - -func (f *FriendRequestMgo) Exist(ctx context.Context, userID string) (exist bool, err error) { - //TODO implement me - panic("implement me") + filter := bson.M{"$or": []bson.M{ + {"from_user_id": fromUserID, "to_user_id": toUserID}, + {"from_user_id": toUserID, "to_user_id": fromUserID}, + }} + return mgotool.Find[*relation.FriendRequestModel](ctx, f.coll, filter) } func (f *FriendRequestMgo) Create(ctx context.Context, friendRequests []*relation.FriendRequestModel) error { diff --git a/pkg/common/db/table/relation/friend_request.go b/pkg/common/db/table/relation/friend_request.go index 18f06817e..40e02c9e1 100644 --- a/pkg/common/db/table/relation/friend_request.go +++ b/pkg/common/db/table/relation/friend_request.go @@ -52,6 +52,4 @@ type FriendRequestModelInterface interface { // Get list of friend requests sent by fromUserID FindFromUserID(ctx context.Context, fromUserID string, pagination pagination.Pagination) (total int64, friendRequests []*FriendRequestModel, err error) FindBothFriendRequests(ctx context.Context, fromUserID, toUserID string) (friends []*FriendRequestModel, err error) - // Check if the record exists - Exist(ctx context.Context, userID string) (exist bool, err error) }