tailly_back_v2/internal/http/graph/post_resolvers.go
madipo2611 a5a90bed7e v0.0.1
2025-04-28 15:14:02 +03:00

49 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package graph
import (
"context"
"tailly_back_v2/internal/domain"
)
type postResolver struct{ *Resolver }
// Author is the resolver for the author field.
func (r *postResolver) Author(ctx context.Context, obj *domain.Post) (*domain.User, error) {
return r.services.User.GetByID(ctx, obj.AuthorID)
}
// Comments is the resolver for the comments field.
func (r *postResolver) Comments(ctx context.Context, obj *domain.Post) ([]*domain.Comment, error) {
return r.services.Comment.GetByPostID(ctx, obj.ID)
}
// Likes is the resolver for the likes field.
func (r *postResolver) Likes(ctx context.Context, obj *domain.Post) ([]*domain.Like, error) {
return r.services.Like.GetByPostID(ctx, obj.ID)
}
// Post.likesCount - получение количества лайков для поста
func (r *postResolver) LikesCount(ctx context.Context, obj *domain.Post) (int, error) {
return r.services.Like.GetCountForPost(ctx, obj.ID)
}
// Post.isLiked - проверка, поставил ли текущий пользователь лайк
func (r *postResolver) IsLiked(ctx context.Context, obj *domain.Post) (bool, error) {
userID, err := getUserIDFromContext(ctx)
if err != nil {
return false, nil // Не авторизован - считаем что не лайкал
}
return r.services.Like.CheckIfLiked(ctx, userID, obj.ID)
}
// CreatedAt is the resolver for the createdAt field.
func (r *postResolver) CreatedAt(ctx context.Context, obj *domain.Post) (string, error) {
panic("not implemented")
}
// UpdatedAt is the resolver for the updatedAt field.
func (r *postResolver) UpdatedAt(ctx context.Context, obj *domain.Post) (string, error) {
panic("not implemented")
}