From 3a3407f85e2663226fc4ad013a81e5acd0160095 Mon Sep 17 00:00:00 2001 From: Untone Date: Sat, 2 Mar 2024 14:14:54 +0300 Subject: [PATCH] type-fix-3 --- server/memorystore/providers/redis/store.go | 27 ++++++++------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/server/memorystore/providers/redis/store.go b/server/memorystore/providers/redis/store.go index e680e76..4560b2c 100644 --- a/server/memorystore/providers/redis/store.go +++ b/server/memorystore/providers/redis/store.go @@ -219,7 +219,6 @@ func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) { return data == "1", nil } - type AuthorProfile struct { ID int `json:"id"` // Add other fields as necessary @@ -230,30 +229,24 @@ type AuthorProfile struct { func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId)).Result() if err != nil { - return "", err + return "", err } - // Parse userProfileString into a UserProfile struct - 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(authorProfileString), &authorProfile.ID) - } + // Parse authorProfileString into a map + var authorProfileMap map[string]interface{} + err = json.Unmarshal([]byte(authorProfileString), &authorProfileMap) if err != nil { return "", err } - // Use userProfile.ID here if necessary - 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)) + // Use authorProfileMap["id"] here if necessary + authorId := int(authorProfileMap["id"].(float64)) // convert float64 to int + authorFollowsAuthorsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:follows-authors`, authorId)) + authorFollowsTopicsString := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:follows-topics`, authorId)) + authorFollowers := c.store.Get(c.ctx, fmt.Sprintf(`author:%d:followers`, authorId)) // Combine user data into a JSON string - combinedData := fmt.Sprintf( - `{"profile": %s, "authors": %s, "topics": %s, "followers": %s}`, + combinedData := fmt.Sprintf(`{"profile": %s, "authors": %s, "topics": %s, "followers": %s}`, authorProfileString, authorFollowsAuthorsString, authorFollowsTopicsString, authorFollowers) - return combinedData, nil }