v0.0.13 Скорректирован метод Comments в postResolver
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d0ff0eeadf
commit
6758e706f2
@ -3,6 +3,7 @@ package graph
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"tailly_back_v2/internal/domain"
|
||||
"time"
|
||||
)
|
||||
@ -46,9 +47,23 @@ func (r *postResolver) Author(ctx context.Context, obj *domain.Post) (*domain.Us
|
||||
|
||||
// Comments is the resolver for the comments field.
|
||||
func (r *postResolver) Comments(ctx context.Context, obj *domain.Post) ([]*domain.Comment, error) {
|
||||
// This would use a CommentService to fetch comments for the post
|
||||
// For now, return empty slice as comment service isn't shown
|
||||
return []*domain.Comment{}, nil
|
||||
log.Printf("Вызов резолвера Comments для поста %d", obj.ID)
|
||||
|
||||
// Логируем контекст
|
||||
if user, ok := ctx.Value("user").(*domain.User); ok {
|
||||
log.Printf("Пользователь: %d", user.ID)
|
||||
} else {
|
||||
log.Println("Пользователь не авторизован")
|
||||
}
|
||||
|
||||
comments, err := r.Services.Comment.GetByPostID(ctx, obj.ID)
|
||||
if err != nil {
|
||||
log.Printf("Ошибка получения комментариев: %v", err)
|
||||
return nil, fmt.Errorf("failed to get comments: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("Найдено комментариев: %d", len(comments))
|
||||
return comments, nil
|
||||
}
|
||||
|
||||
// Likes is the resolver for the likes field.
|
||||
|
||||
@ -85,7 +85,6 @@ func (s *commentService) GetByPostID(ctx context.Context, postID int) ([]*domain
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
comments, err := s.commentRepo.GetByPostID(ctx, postID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user