update user command

pull/1532/head
AndrewZuo01 2 years ago
parent 5351e4d554
commit e0d17df248

@ -155,7 +155,6 @@ require (
gopkg.in/ini.v1 v1.67.0 // indirect
)
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
DeleteUserCommand(ctx context.Context, userID string, Type int32, UUID 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 {
@ -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 {
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)
return commands, err
}

@ -109,7 +109,7 @@ func (u *UserMgo) UpdateUserCommand(ctx context.Context, userID string, Type int
_, err := collection.UpdateOne(ctx, filter, update)
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")
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)
commands := make(map[string]user.CommandInfo)
var commands []user.CommandInfoResp
for cursor.Next(ctx) {
var result UserCommand // Assuming UserCommand includes a map or similar structure
err = cursor.Decode(&result)
if err != nil {
return nil, err
var commandInfo user.CommandInfoResp
// Define a struct that represents your MongoDB document structure
var document struct {
UUID string `bson:"uuid"`
Value string `bson:"value"`
CreateTime int64 `bson:"createTime"`
}
for key, command := range result.Commands {
commands[key] = command
if err := cursor.Decode(&document); err != nil {
return nil, err
}
// Populate the user.CommandInfoResp struct with the required fields
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

@ -65,5 +65,5 @@ type UserModelInterface interface {
AddUserCommand(ctx context.Context, userID string, Type int32, UUID string, value 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
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…
Cancel
Save