type-fix-3
This commit is contained in:
parent
7a1df30325
commit
3a3407f85e
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user