update user command get

This commit is contained in:
AndrewZuo01 2023-12-13 09:43:23 +08:00
parent c014ad173c
commit 6b151f0106
4 changed files with 7 additions and 9 deletions

View File

@ -378,10 +378,8 @@ func (s *userServer) ProcessUserCommandGet(ctx context.Context, req *pbuser.Proc
// Initialize commandInfoSlice as an empty slice
commandInfoSlice := make([]*pbuser.CommandInfoResp, 0, len(commands))
for i := range commands {
// Access each command using index to avoid copying the struct
command := &commands[i] // Change here: use a pointer to the struct to avoid copying
for _, command := range commands {
// No need to use index since command is already a pointer
commandInfoSlice = append(commandInfoSlice, &pbuser.CommandInfoResp{
Uuid: command.Uuid,
Value: command.Value,

View File

@ -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) ([]user.CommandInfoResp, 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) ([]user.CommandInfoResp, error) {
commands, err := u.userDB.GetUserCommands(ctx, userID, Type)
func (u *userDatabase) GetUserCommands(ctx context.Context, userID string, Type int32) ([]*user.CommandInfoResp, error) {
commands, err := u.userDB.GetUserCommand(ctx, userID, Type)
return commands, err
}

View File

@ -106,7 +106,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) ([]*user.CommandInfoResp, error) {
func (u *UserMgo) GetUserCommand(ctx context.Context, userID string, Type int32) ([]*user.CommandInfoResp, error) {
collection := u.coll.Database().Collection("userCommands")
filter := bson.M{"userID": userID, "type": Type}

View File

@ -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) ([]user.CommandInfoResp, error)
GetUserCommand(ctx context.Context, userID string, Type int32) ([]*user.CommandInfoResp, error)
}