octoposprime / op-be-graphql

OctopOS Prime Backend Api Gateway
http://www.octoposprime.com
MIT License
13 stars 1 forks source link

Improvements to the UpdateUserBase Function #67

Closed Smnrgcl closed 3 months ago

Smnrgcl commented 3 months ago

We need to make the following changes in the file located at 'pkg/infrastructure/adapter/service/user.go'.

I propose two key improvements for the UpdateUserBase function:

Update Log Messages: The function name "UpdateUserBase" should be explicitly mentioned in the logs.

func (a ServiceAdapter) UpdateUserBase(ctx context.Context, user *pb.User) (*pb.User, error) {
    conn, err := grpc.Dial(tconfig.GetInternalConfigInstance().Grpc.UserHost+":"+tconfig.GetInternalConfigInstance().Grpc.UserPort, grpc.WithTransportCredentials(insecure.NewCredentials()))
    if err != nil {
        userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateUserBase", userId, err.Error()))
        return &pb.User{}, err
    }

    userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
    ctx = metadata.AppendToOutgoingContext(ctx, string(smodel.QueryKeyUid), userId)
    pbResult, err := pb.NewUserSvcClient(conn).UpdateUserBase(ctx, user)
    if err != nil {
        userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateUserBase", userId, err.Error()))
        return &pb.User{}, err
    }
    return pbResult, nil
}

Correct Code Formatting: Some expressions need to be reformatted for better readability. These changes will enhance the understandability and consistency of our code.