get-id
All checks were successful
deploy / deploy (push) Successful in 1m26s

This commit is contained in:
Untone 2024-06-05 23:40:09 +03:00
parent bfa192d21e
commit e9f54a74f0

View File

@ -3,9 +3,7 @@ package redis
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"strings"
"time" "time"
"errors"
"encoding/json" "encoding/json"
"github.com/authorizerdev/authorizer/server/constants" "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, // 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. // and assigns the JSON string to the provided user's ID.
func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) { func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) {
// Получаем профиль автора из Redis // Получаем ID автора из Redis
rkey := fmt.Sprintf("author:user:%s", strings.TrimSpace(userId)) authorIdString, err := c.store.Get(c.ctx, fmt.Sprintf("author:user:%s", userId)).Result()
authorProfileString, err := c.store.Get(c.ctx, rkey).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 { if err != nil {
fmt.Println("redis GET:", rkey)
fmt.Println(authorProfileString)
return "", err return "", err
} }
@ -248,13 +256,6 @@ func (c *provider) GetUserAppDataFromRedis(userId string) (string, error) {
return "", err 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 // Начинаем сбор данных в общий JSON
combinedData := map[string]interface{}{ combinedData := map[string]interface{}{
"profile": authorProfileMap, "profile": authorProfileMap,