49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
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")
|
||
}
|