From 7a1df30325f973ce8d140a9a6c3544d31d3c6503 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 2 Mar 2024 14:06:20 +0300 Subject: [PATCH] type-fix --- server/memorystore/providers/redis/store.go | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index 48d1e42..e680e76 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -220,40 +220,40 @@ func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) { return data == "1", nil } -type UserProfile struct { - ID string `json:"id"` +type AuthorProfile struct { + ID int `json:"id"` // Add other fields as necessary } // GetUserAppDataFromRedis retrieves user profile and follows from Redis, combines them into a JSON format, // and assigns the JSON string to the provided user's ID. func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { - userProfileString, err := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId)).Result() + authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId)).Result() if err != nil { return "", err } // Parse userProfileString into a UserProfile struct - var userProfile UserProfile - err = json.Unmarshal([]byte(userProfileString), &userProfile.ID) + var authorProfile AuthorProfile + err = json.Unmarshal([]byte(authorProfileString), &authorProfile.ID) if err != nil { // If the ID is not a number, try unmarshalling it as a string instead - err = json.Unmarshal([]byte(userProfileString), &userProfile.ID) + err = json.Unmarshal([]byte(authorProfileString), &authorProfile.ID) } if err != nil { return "", err } // Use userProfile.ID here if necessary - authorId := userProfile.ID - userFollowsAuthors := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-authors`, authorId)) - userFollowsTopics := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-topics`, authorId)) - userFollowers := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:followers`, authorId)) + authorId := authorProfile.ID + authorFollowsAuthorsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-authors`, authorId)) + authorFollowsTopicsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:follows-topics`, authorId)) + authorFollowers := c.store.Get(c.ctx, fmt.Sprintf(`author:%s:followers`, authorId)) // Combine user data into a JSON string combinedData := fmt.Sprintf( `{"profile": %s, "authors": %s, "topics": %s, "followers": %s}`, - userProfile, userFollowsAuthors, userFollowsTopics, userFollowers) + authorProfileString, authorFollowsAuthorsString, authorFollowsTopicsString, authorFollowers) return combinedData, nil }