mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 02:16:16 +08:00
errcode
This commit is contained in:
parent
5bb731f884
commit
803ecd3f92
@ -56,7 +56,7 @@ func NewGroupServer(port int) *groupServer {
|
|||||||
etcdAddr: config.Config.Etcd.EtcdAddr,
|
etcdAddr: config.Config.Etcd.EtcdAddr,
|
||||||
}
|
}
|
||||||
ttl := 10
|
ttl := 10
|
||||||
etcdClient, err := getcdv3.NewEtcdConn(g.rpcRegisterName, strings.Join(g.etcdAddr, ","), config.Config.RpcRegisterIP, config.Config.Etcd.UserName, config.Config.Etcd.Password, port, ttl)
|
etcdClient, err := getcdv3.NewEtcdConn(config.Config.Etcd.EtcdSchema, strings.Join(g.etcdAddr, ","), config.Config.RpcRegisterIP, config.Config.Etcd.UserName, config.Config.Etcd.Password, port, ttl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("NewEtcdConn failed" + err.Error())
|
panic("NewEtcdConn failed" + err.Error())
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ import (
|
|||||||
"Open_IM/pkg/proto/group"
|
"Open_IM/pkg/proto/group"
|
||||||
"context"
|
"context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GroupLocalCache struct {
|
type GroupLocalCache struct {
|
||||||
|
lock sync.Mutex
|
||||||
cache map[string]GroupMemberIDsHash
|
cache map[string]GroupMemberIDsHash
|
||||||
rpc *grpc.ClientConn
|
rpc *grpc.ClientConn
|
||||||
group group.GroupClient
|
group group.GroupClient
|
||||||
@ -26,7 +28,7 @@ func NewGroupMemberIDsLocalCache(rpc *grpc.ClientConn) GroupLocalCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string {
|
func (g *GroupLocalCache) GetGroupMemberIDs(ctx context.Context, groupID string) []string {
|
||||||
_, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
resp, err := g.group.GetGroupAbstractInfo(ctx, &group.GetGroupAbstractInfoReq{
|
||||||
GroupIDs: nil,
|
GroupIDs: nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -58,7 +58,6 @@ func (c *ChatLog) Create(msg pbMsg.MsgDataToMQ) error {
|
|||||||
EmitDefaults: false,
|
EmitDefaults: false,
|
||||||
}
|
}
|
||||||
chatLog.Content, _ = marshaler.MarshalToString(&tips)
|
chatLog.Content, _ = marshaler.MarshalToString(&tips)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
chatLog.Content = string(msg.MsgData.Content)
|
chatLog.Content = string(msg.MsgData.Content)
|
||||||
}
|
}
|
||||||
|
56
pkg/common/db/table/unrelation.go
Normal file
56
pkg/common/db/table/unrelation.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
package table
|
||||||
|
|
||||||
|
type SuperGroup struct {
|
||||||
|
GroupID string `bson:"group_id" json:"groupID"`
|
||||||
|
MemberIDList []string `bson:"member_id_list" json:"memberIDList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserToSuperGroup struct {
|
||||||
|
UserID string `bson:"user_id" json:"userID"`
|
||||||
|
GroupIDList []string `bson:"group_id_list" json:"groupIDList"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
TagID string `bson:"tag_id"`
|
||||||
|
TagName string `bson:"tag_name"`
|
||||||
|
UserList []string `bson:"user_list"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CommonUser struct {
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
UserName string `bson:"user_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type TagSendLog struct {
|
||||||
|
UserList []CommonUser `bson:"tag_list"`
|
||||||
|
SendID string `bson:"send_id"`
|
||||||
|
SenderPlatformID int32 `bson:"sender_platform_id"`
|
||||||
|
Content string `bson:"content"`
|
||||||
|
SendTime int64 `bson:"send_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WorkMoment struct {
|
||||||
|
WorkMomentID string `bson:"work_moment_id"`
|
||||||
|
UserID string `bson:"user_id"`
|
||||||
|
UserName string `bson:"user_name"`
|
||||||
|
FaceURL string `bson:"face_url"`
|
||||||
|
Content string `bson:"content"`
|
||||||
|
LikeUserList []*CommonUser `bson:"like_user_list"`
|
||||||
|
AtUserList []*CommonUser `bson:"at_user_list"`
|
||||||
|
PermissionUserList []*CommonUser `bson:"permission_user_list"`
|
||||||
|
Comments []*CommonUser `bson:"comments"`
|
||||||
|
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
||||||
|
Permission int32 `bson:"permission"`
|
||||||
|
CreateTime int32 `bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Comment struct {
|
||||||
|
UserID string `bson:"user_id" json:"user_id"`
|
||||||
|
UserName string `bson:"user_name" json:"user_name"`
|
||||||
|
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
||||||
|
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
||||||
|
ContentID string `bson:"content_id" json:"content_id"`
|
||||||
|
Content string `bson:"content" json:"content"`
|
||||||
|
CreateTime int32 `bson:"create_time" json:"create_time"`
|
||||||
|
}
|
@ -3,6 +3,7 @@ package unrelation
|
|||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
"Open_IM/pkg/common/constant"
|
"Open_IM/pkg/common/constant"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -22,57 +23,12 @@ type OfficeMgoDB struct {
|
|||||||
WorkMomentCollection *mongo.Collection
|
WorkMomentCollection *mongo.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tag struct {
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
TagID string `bson:"tag_id"`
|
|
||||||
TagName string `bson:"tag_name"`
|
|
||||||
UserList []string `bson:"user_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type commonUser struct {
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
UserName string `bson:"user_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TagSendLog struct {
|
|
||||||
UserList []commonUser `bson:"tag_list"`
|
|
||||||
SendID string `bson:"send_id"`
|
|
||||||
SenderPlatformID int32 `bson:"sender_platform_id"`
|
|
||||||
Content string `bson:"content"`
|
|
||||||
SendTime int64 `bson:"send_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type WorkMoment struct {
|
|
||||||
WorkMomentID string `bson:"work_moment_id"`
|
|
||||||
UserID string `bson:"user_id"`
|
|
||||||
UserName string `bson:"user_name"`
|
|
||||||
FaceURL string `bson:"face_url"`
|
|
||||||
Content string `bson:"content"`
|
|
||||||
LikeUserList []*commonUser `bson:"like_user_list"`
|
|
||||||
AtUserList []*commonUser `bson:"at_user_list"`
|
|
||||||
PermissionUserList []*commonUser `bson:"permission_user_list"`
|
|
||||||
Comments []*commonUser `bson:"comments"`
|
|
||||||
PermissionUserIDList []string `bson:"permission_user_id_list"`
|
|
||||||
Permission int32 `bson:"permission"`
|
|
||||||
CreateTime int32 `bson:"create_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Comment struct {
|
|
||||||
UserID string `bson:"user_id" json:"user_id"`
|
|
||||||
UserName string `bson:"user_name" json:"user_name"`
|
|
||||||
ReplyUserID string `bson:"reply_user_id" json:"reply_user_id"`
|
|
||||||
ReplyUserName string `bson:"reply_user_name" json:"reply_user_name"`
|
|
||||||
ContentID string `bson:"content_id" json:"content_id"`
|
|
||||||
Content string `bson:"content" json:"content"`
|
|
||||||
CreateTime int32 `bson:"create_time" json:"create_time"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewOfficeMgoDB(mgoDB *mongo.Database) *OfficeMgoDB {
|
func NewOfficeMgoDB(mgoDB *mongo.Database) *OfficeMgoDB {
|
||||||
return &OfficeMgoDB{mgoDB: mgoDB, TagCollection: mgoDB.Collection(cTag), TagSendLogCollection: mgoDB.Collection(cSendLog), WorkMomentCollection: mgoDB.Collection(cSendLog)}
|
return &OfficeMgoDB{mgoDB: mgoDB, TagCollection: mgoDB.Collection(cTag), TagSendLogCollection: mgoDB.Collection(cSendLog), WorkMomentCollection: mgoDB.Collection(cSendLog)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]Tag, error) {
|
func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]table.Tag, error) {
|
||||||
var tags []Tag
|
var tags []table.Tag
|
||||||
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
cursor, err := db.TagCollection.Find(ctx, bson.M{"user_id": userID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return tags, err
|
return tags, err
|
||||||
@ -85,7 +41,7 @@ func (db *OfficeMgoDB) GetUserTags(ctx context.Context, userID string) ([]Tag, e
|
|||||||
|
|
||||||
func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, userList []string) error {
|
||||||
tagID := generateTagID(tagName, userID)
|
tagID := generateTagID(tagName, userID)
|
||||||
tag := Tag{
|
tag := table.Tag{
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
TagID: tagID,
|
TagID: tagID,
|
||||||
TagName: tagName,
|
TagName: tagName,
|
||||||
@ -95,8 +51,8 @@ func (db *OfficeMgoDB) CreateTag(ctx context.Context, userID, tagName string, us
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetTagByID(ctx context.Context, userID, tagID string) (Tag, error) {
|
func (db *OfficeMgoDB) GetTagByID(ctx context.Context, userID, tagID string) (table.Tag, error) {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||||
return tag, err
|
return tag, err
|
||||||
}
|
}
|
||||||
@ -107,7 +63,7 @@ func (db *OfficeMgoDB) DeleteTag(ctx context.Context, userID, tagID string) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string, increaseUserIDList []string, reduceUserIDList []string) error {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
if err := db.TagCollection.FindOne(ctx, bson.M{"tag_id": tagID, "user_id": userID}).Decode(&tag); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -140,18 +96,18 @@ func (db *OfficeMgoDB) SetTag(ctx context.Context, userID, tagID, newName string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
func (db *OfficeMgoDB) GetUserIDListByTagID(ctx context.Context, userID, tagID string) ([]string, error) {
|
||||||
var tag Tag
|
var tag table.Tag
|
||||||
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
err := db.TagCollection.FindOne(ctx, bson.M{"user_id": userID, "tag_id": tagID}).Decode(&tag)
|
||||||
return tag.UserList, err
|
return tag.UserList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) SaveTagSendLog(ctx context.Context, tagSendLog *TagSendLog) error {
|
func (db *OfficeMgoDB) SaveTagSendLog(ctx context.Context, tagSendLog *table.TagSendLog) error {
|
||||||
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
_, err := db.TagSendLogCollection.InsertOne(ctx, tagSendLog)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]TagSendLog, error) {
|
func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.TagSendLog, error) {
|
||||||
var tagSendLogs []TagSendLog
|
var tagSendLogs []table.TagSendLog
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"send_time": -1})
|
||||||
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
cursor, err := db.TagSendLogCollection.Find(ctx, bson.M{"send_id": userID}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -161,7 +117,7 @@ func (db *OfficeMgoDB) GetTagSendLogs(ctx context.Context, userID string, showNu
|
|||||||
return tagSendLogs, err
|
return tagSendLogs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *WorkMoment) error {
|
func (db *OfficeMgoDB) CreateOneWorkMoment(ctx context.Context, workMoment *table.WorkMoment) error {
|
||||||
workMomentID := generateWorkMomentID(workMoment.UserID)
|
workMomentID := generateWorkMomentID(workMoment.UserID)
|
||||||
workMoment.WorkMomentID = workMomentID
|
workMoment.WorkMomentID = workMomentID
|
||||||
workMoment.CreateTime = int32(time.Now().Unix())
|
workMoment.CreateTime = int32(time.Now().Unix())
|
||||||
@ -184,13 +140,13 @@ func (db *OfficeMgoDB) DeleteComment(ctx context.Context, workMomentID, contentI
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetWorkMomentByID(ctx context.Context, workMomentID string) (*WorkMoment, error) {
|
func (db *OfficeMgoDB) GetWorkMomentByID(ctx context.Context, workMomentID string) (*table.WorkMoment, error) {
|
||||||
workMoment := &WorkMoment{}
|
workMoment := &table.WorkMoment{}
|
||||||
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
err := db.WorkMomentCollection.FindOne(ctx, bson.M{"work_moment_id": workMomentID}).Decode(workMoment)
|
||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*WorkMoment, bool, error) {
|
func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userName, workMomentID string) (*table.WorkMoment, bool, error) {
|
||||||
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
workMoment, err := db.GetWorkMomentByID(ctx, workMomentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
@ -203,7 +159,7 @@ func (db *OfficeMgoDB) LikeOneWorkMoment(ctx context.Context, likeUserID, userNa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isAlreadyLike {
|
if !isAlreadyLike {
|
||||||
workMoment.LikeUserList = append(workMoment.LikeUserList, &commonUser{UserID: likeUserID, UserName: userName})
|
workMoment.LikeUserList = append(workMoment.LikeUserList, &table.CommonUser{UserID: likeUserID, UserName: userName})
|
||||||
}
|
}
|
||||||
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
_, err = db.WorkMomentCollection.UpdateOne(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$set": bson.M{"like_user_list": workMoment.LikeUserList}})
|
||||||
return workMoment, !isAlreadyLike, err
|
return workMoment, !isAlreadyLike, err
|
||||||
@ -213,15 +169,15 @@ func (db *OfficeMgoDB) SetUserWorkMomentsLevel(ctx context.Context, userID strin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) CommentOneWorkMoment(ctx context.Context, comment *Comment, workMomentID string) (WorkMoment, error) {
|
func (db *OfficeMgoDB) CommentOneWorkMoment(ctx context.Context, comment *table.Comment, workMomentID string) (table.WorkMoment, error) {
|
||||||
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
comment.ContentID = generateWorkMomentCommentID(workMomentID)
|
||||||
var workMoment WorkMoment
|
var workMoment table.WorkMoment
|
||||||
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
err := db.WorkMomentCollection.FindOneAndUpdate(ctx, bson.M{"work_moment_id": workMomentID}, bson.M{"$push": bson.M{"comments": comment}}).Decode(&workMoment)
|
||||||
return workMoment, err
|
return workMoment, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]WorkMoment, error) {
|
func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string, showNumber, pageNumber int32) ([]table.WorkMoment, error) {
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []table.WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
result, err := db.WorkMomentCollection.Find(ctx, bson.M{"user_id": userID}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -231,8 +187,8 @@ func (db *OfficeMgoDB) GetUserSelfWorkMoments(ctx context.Context, userID string
|
|||||||
return workMomentList, err
|
return workMomentList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]WorkMoment, error) {
|
func (db *OfficeMgoDB) GetUserWorkMoments(ctx context.Context, opUserID, userID string, showNumber, pageNumber int32, friendIDList []string) ([]table.WorkMoment, error) {
|
||||||
var workMomentList []WorkMoment
|
var workMomentList []table.WorkMoment
|
||||||
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
findOpts := options.Find().SetLimit(int64(showNumber)).SetSkip(int64(showNumber) * (int64(pageNumber) - 1)).SetSort(bson.M{"create_time": -1})
|
||||||
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
result, err := db.WorkMomentCollection.Find(ctx, bson.D{ // 等价条件: select * from
|
||||||
{"user_id", userID},
|
{"user_id", userID},
|
||||||
|
@ -2,6 +2,7 @@ package unrelation
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/db/table"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
"context"
|
"context"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -22,23 +23,13 @@ type SuperGroupMgoDB struct {
|
|||||||
userToSuperGroupCollection *mongo.Collection
|
userToSuperGroupCollection *mongo.Collection
|
||||||
}
|
}
|
||||||
|
|
||||||
type SuperGroup struct {
|
|
||||||
GroupID string `bson:"group_id" json:"groupID"`
|
|
||||||
MemberIDList []string `bson:"member_id_list" json:"memberIDList"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type UserToSuperGroup struct {
|
|
||||||
UserID string `bson:"user_id" json:"userID"`
|
|
||||||
GroupIDList []string `bson:"group_id_list" json:"groupIDList"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewSuperGroupMgoDB(mgoClient *mongo.Client) *SuperGroupMgoDB {
|
func NewSuperGroupMgoDB(mgoClient *mongo.Client) *SuperGroupMgoDB {
|
||||||
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
mgoDB := mgoClient.Database(config.Config.Mongo.DBDatabase)
|
||||||
return &SuperGroupMgoDB{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(cSuperGroup), userToSuperGroupCollection: mgoDB.Collection(cUserToSuperGroup)}
|
return &SuperGroupMgoDB{MgoDB: mgoDB, MgoClient: mgoClient, superGroupCollection: mgoDB.Collection(cSuperGroup), userToSuperGroupCollection: mgoDB.Collection(cUserToSuperGroup)}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID string, initMemberIDList []string) error {
|
||||||
superGroup := SuperGroup{
|
superGroup := table.SuperGroup{
|
||||||
GroupID: groupID,
|
GroupID: groupID,
|
||||||
MemberIDList: initMemberIDList,
|
MemberIDList: initMemberIDList,
|
||||||
}
|
}
|
||||||
@ -60,8 +51,8 @@ func (db *SuperGroupMgoDB) CreateSuperGroup(sCtx mongo.SessionContext, groupID s
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) GetSuperGroup(ctx context.Context, groupID string) (*SuperGroup, error) {
|
func (db *SuperGroupMgoDB) GetSuperGroup(ctx context.Context, groupID string) (*table.SuperGroup, error) {
|
||||||
superGroup := SuperGroup{}
|
superGroup := table.SuperGroup{}
|
||||||
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
err := db.superGroupCollection.FindOne(ctx, bson.M{"group_id": groupID}).Decode(&superGroup)
|
||||||
return &superGroup, err
|
return &superGroup, err
|
||||||
}
|
}
|
||||||
@ -106,8 +97,8 @@ func (db *SuperGroupMgoDB) RemoverUserFromSuperGroup(ctx context.Context, groupI
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID string) (*UserToSuperGroup, error) {
|
func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID string) (*table.UserToSuperGroup, error) {
|
||||||
var user UserToSuperGroup
|
var user table.UserToSuperGroup
|
||||||
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
err := db.userToSuperGroupCollection.FindOne(ctx, bson.M{"user_id": userID}).Decode(&user)
|
||||||
return &user, utils.Wrap(err, "")
|
return &user, utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
@ -115,7 +106,7 @@ func (db *SuperGroupMgoDB) GetSuperGroupByUserID(ctx context.Context, userID str
|
|||||||
func (db *SuperGroupMgoDB) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
func (db *SuperGroupMgoDB) DeleteSuperGroup(ctx context.Context, groupID string) error {
|
||||||
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
opts := options.Session().SetDefaultReadConcern(readconcern.Majority())
|
||||||
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
return db.MgoDB.Client().UseSessionWithOptions(ctx, opts, func(sCtx mongo.SessionContext) error {
|
||||||
superGroup := &SuperGroup{}
|
superGroup := &table.SuperGroup{}
|
||||||
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
_, err := db.superGroupCollection.DeleteOne(sCtx, bson.M{"group_id": groupID})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = sCtx.AbortTransaction(ctx)
|
_ = sCtx.AbortTransaction(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user