type-fix-3

This commit is contained in:
Untone 2024-03-02 14:14:54 +03:00
parent 7a1df30325
commit 3a3407f85e

View File

@ -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
@ -233,27 +232,21 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) {
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
}