v0.0.30.3 Добавлено логирование в получение клипов и авторов
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
admin 2025-09-02 23:35:28 +03:00
parent 8320de7d6e
commit e5f4f41856

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"log"
"tailly_back_v2/internal/domain" "tailly_back_v2/internal/domain"
"tailly_back_v2/proto" "tailly_back_v2/proto"
"time" "time"
@ -31,12 +32,33 @@ func (r *clipResolver) IsLiked(ctx context.Context, obj *domain.Clip) (bool, err
func (r *clipResolver) Author(ctx context.Context, obj *domain.Clip) (*domain.User, error) { func (r *clipResolver) Author(ctx context.Context, obj *domain.Clip) (*domain.User, error) {
if obj.AuthorID == 0 { if obj.AuthorID == 0 {
return nil, fmt.Errorf("clip has no author ID") log.Printf("ERROR: Clip %d has no author ID", obj.ID)
return &domain.User{
ID: 0,
Username: "Unknown",
Avatar: "/img/logo.png",
}, nil
// Не возвращаем ошибку, чтобы не ломать весь запрос
} }
author, err := r.Services.User.GetByID(ctx, obj.AuthorID) author, err := r.Services.User.GetByID(ctx, obj.AuthorID)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to get author: %w", err) log.Printf("ERROR: Failed to get author %d for clip %d: %v", obj.AuthorID, obj.ID, err)
// Возвращаем заглушку вместо ошибки
return &domain.User{
ID: obj.AuthorID,
Username: "Unknown",
Avatar: "/img/logo.png",
}, nil
}
if author == nil {
log.Printf("ERROR: Author %d not found for clip %d", obj.AuthorID, obj.ID)
return &domain.User{
ID: obj.AuthorID,
Username: "Deleted User",
Avatar: "/img/logo.png",
}, nil
} }
return author, nil return author, nil
@ -219,10 +241,20 @@ func (r *queryResolver) Clips(ctx context.Context, limit *int, offset *int) ([]*
Offset: int32(offsetVal), Offset: int32(offsetVal),
}) })
if err != nil { if err != nil {
log.Printf("ERROR: Failed to get clips from gRPC service: %v", err)
return nil, fmt.Errorf("failed to get clips: %w", err) return nil, fmt.Errorf("failed to get clips: %w", err)
} }
return r.protoClipsToDomain(resp.Clips), nil clips := r.protoClipsToDomain(resp.Clips)
// Добавьте логирование для дебага
log.Printf("Retrieved %d clips from gRPC service", len(clips))
for i, clip := range clips {
log.Printf("Clip %d: ID=%d, Title=%s, VideoURL=%s, AuthorID=%d",
i, clip.ID, clip.Title, clip.VideoURL, clip.AuthorID)
}
return clips, nil
} }
// UserClips is the resolver for the userClips field. // UserClips is the resolver for the userClips field.