This commit is contained in:
parent
bfa192d21e
commit
e9f54a74f0
|
@ -3,9 +3,7 @@ package redis
|
|||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"errors"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/authorizerdev/authorizer/server/constants"
|
||||
|
@ -232,12 +230,22 @@ type AuthorProfile struct {
|
|||
// 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) {
|
||||
// Получаем профиль автора из Redis
|
||||
rkey := fmt.Sprintf("author:user:%s", strings.TrimSpace(userId))
|
||||
authorProfileString, err := c.store.Get(c.ctx, rkey).Result()
|
||||
// Получаем ID автора из Redis
|
||||
authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Преобразуем ID автора из строки в int
|
||||
var authorId int
|
||||
err = json.Unmarshal([]byte(authorIdString), &authorId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Получаем профиль автора из Redis
|
||||
authorProfileString, err := c.store.Get(c.ctx, fmt.Sprintf("author:id:%d", authorId)).Result()
|
||||
if err != nil {
|
||||
fmt.Println("redis GET:", rkey)
|
||||
fmt.Println(authorProfileString)
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
@ -248,13 +256,6 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
authorIdFloat, ok := authorProfileMap["id"].(float64)
|
||||
if !ok {
|
||||
return "", errors.New("id not found or is of incorrect type")
|
||||
}
|
||||
authorId := int(authorIdFloat)
|
||||
fmt.Println("author id:", authorId)
|
||||
|
||||
// Начинаем сбор данных в общий JSON
|
||||
combinedData := map[string]interface{}{
|
||||
"profile": authorProfileMap,
|
||||
|
|
Loading…
Reference in New Issue
Block a user