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