appdata-debug

This commit is contained in:
Untone 2024-03-02 09:56:48 +03:00
parent 31079f2628
commit ce5b09953e
3 changed files with 27 additions and 4 deletions

View File

@ -219,15 +219,34 @@ func (c *provider) GetBoolStoreEnvVariable(key string) (bool, error) {
return data == "1", nil
}
type UserProfile struct {
ID string `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) {
// Retrieve user data from Redis
userProfile := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId))
userFollows := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:follows`, userId))
// Retrieve user data from Redis
userProfileString := c.store.Get(c.ctx, fmt.Sprintf(`user:%s:author`, userId))
// Parse userProfileString into a UserProfile struct
var userProfile UserProfile
err := json.Unmarshal([]byte(userProfileString), &userProfile)
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))
// Combine user data into a JSON string
combinedData := fmt.Sprintf(`{"profile": %s, "follows": %s}`, userProfile, userFollows)
combinedData := fmt.Sprintf(
`{"profile": %s, "authors": %s, "topics": %s, "followers": %s}`,
userProfile, userFollowsAuthors, userFollowsTopics, userFollowers)
return combinedData, nil
}

View File

@ -320,6 +320,8 @@ func LoginResolver(ctx context.Context, params model.LoginInput) (*model.AuthRes
if err == nil {
// Assign the combined data to the provided pointer
user.AppData = &appData
} else {
log.Printf("Error getting author's redis cache: %v", err)
}
res = &model.AuthResponse{

View File

@ -94,6 +94,8 @@ func SessionResolver(ctx context.Context, params *model.SessionQueryInput) (*mod
if err == nil {
// Assign the combined data to the provided pointer
user.AppData = &appData
} else {
log.Printf("Error getting author's redis cache: %v", err)
}
res = &model.AuthResponse{