mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 19:02:31 +08:00
update user command
This commit is contained in:
parent
5351e4d554
commit
e0d17df248
3
go.mod
3
go.mod
@ -155,7 +155,6 @@ require (
|
|||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
)
|
)
|
||||||
replace (
|
replace (
|
||||||
github.com/OpenIMSDK/protocol v0.0.32 => github.com/AndrewZuo01/protocol v0.0.0-20231212040759-69dcf194366f
|
github.com/OpenIMSDK/protocol v0.0.32 => github.com/AndrewZuo01/protocol v0.0.0-20231212071940-a88da967f0e2
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -73,7 +73,7 @@ type UserDatabase interface {
|
|||||||
AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
||||||
DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error
|
DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error
|
||||||
UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
||||||
GetUserCommands(ctx context.Context, userID string, Type int32) (map[string]user.CommandInfo, error)
|
GetUserCommands(ctx context.Context, userID string, Type int32) ([]user.CommandInfoResp, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type userDatabase struct {
|
type userDatabase struct {
|
||||||
@ -242,7 +242,7 @@ func (u *userDatabase) DeleteUserCommand(ctx context.Context, userID string, Typ
|
|||||||
func (u *userDatabase) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error {
|
func (u *userDatabase) UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error {
|
||||||
return u.userDB.UpdateUserCommand(ctx, userID, Type, UUID, value)
|
return u.userDB.UpdateUserCommand(ctx, userID, Type, UUID, value)
|
||||||
}
|
}
|
||||||
func (u *userDatabase) GetUserCommands(ctx context.Context, userID string, Type int32) (map[string]user.CommandInfo, error) {
|
func (u *userDatabase) GetUserCommands(ctx context.Context, userID string, Type int32) ([]user.CommandInfoResp, error) {
|
||||||
commands, err := u.userDB.GetUserCommands(ctx, userID, Type)
|
commands, err := u.userDB.GetUserCommands(ctx, userID, Type)
|
||||||
return commands, err
|
return commands, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -109,7 +109,7 @@ func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int
|
|||||||
_, err := collection.UpdateOne(ctx, filter, update)
|
_, err := collection.UpdateOne(ctx, filter, update)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
func (u *UserMgo) GetUserCommands(ctx context.Context, userID string, Type int32) (map[string]user.CommandInfo, error) {
|
func (u *UserMgo) GetUserCommands(ctx context.Context, userID string, Type int32) ([]user.CommandInfoResp, error) {
|
||||||
collection := u.coll.Database().Collection("userCommands")
|
collection := u.coll.Database().Collection("userCommands")
|
||||||
filter := bson.M{"userID": userID, "type": Type}
|
filter := bson.M{"userID": userID, "type": Type}
|
||||||
|
|
||||||
@ -119,17 +119,32 @@ func (u *UserMgo) GetUserCommands(ctx context.Context, userID string, Type int32
|
|||||||
}
|
}
|
||||||
defer cursor.Close(ctx)
|
defer cursor.Close(ctx)
|
||||||
|
|
||||||
commands := make(map[string]user.CommandInfo)
|
var commands []user.CommandInfoResp
|
||||||
|
|
||||||
for cursor.Next(ctx) {
|
for cursor.Next(ctx) {
|
||||||
var result UserCommand // Assuming UserCommand includes a map or similar structure
|
var commandInfo user.CommandInfoResp
|
||||||
err = cursor.Decode(&result)
|
|
||||||
if err != nil {
|
// Define a struct that represents your MongoDB document structure
|
||||||
|
var document struct {
|
||||||
|
UUID string `bson:"uuid"`
|
||||||
|
Value string `bson:"value"`
|
||||||
|
CreateTime int64 `bson:"createTime"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cursor.Decode(&document); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, command := range result.Commands {
|
// Populate the user.CommandInfoResp struct with the required fields
|
||||||
commands[key] = command
|
commandInfo.Uuid = document.UUID
|
||||||
|
commandInfo.Value = document.Value
|
||||||
|
commandInfo.CreateTime = document.CreateTime
|
||||||
|
|
||||||
|
commands = append(commands, commandInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := cursor.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return commands, nil
|
return commands, nil
|
||||||
|
|||||||
@ -65,5 +65,5 @@ type UserModelInterface interface {
|
|||||||
AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
||||||
DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error
|
DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID string) error
|
||||||
UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
UpdateUserCommand(ctx context.Context, userID string, Type int32, UUID string, value string) error
|
||||||
GetUserCommands(ctx context.Context, userID string, Type int32) (map[string]user.CommandInfo, error)
|
GetUserCommands(ctx context.Context, userID string, Type int32) ([]user.CommandInfoResp, error)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user