v0.0.14
This commit is contained in:
parent
f9f1e16b1b
commit
41f9f9679f
File diff suppressed because it is too large
Load Diff
@ -1,22 +0,0 @@
|
|||||||
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
|
|
||||||
|
|
||||||
package graph
|
|
||||||
|
|
||||||
import (
|
|
||||||
"tailly_back_v2/internal/domain"
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatSession struct {
|
|
||||||
User *domain.User `json:"user"`
|
|
||||||
LastMessage *domain.Message `json:"lastMessage"`
|
|
||||||
UnreadCount int `json:"unreadCount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Mutation struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Query struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type Subscription struct {
|
|
||||||
}
|
|
||||||
@ -44,15 +44,6 @@ func (r *postResolver) Author(ctx context.Context, obj *domain.Post) (*domain.Us
|
|||||||
return author, nil
|
return author, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comments is the resolver for the comments field.
|
|
||||||
func (r *postResolver) Comments(ctx context.Context, obj *domain.Post) ([]*domain.Comment, error) {
|
|
||||||
comments, err := r.Services.Comment.GetByPostID(ctx, obj.ID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to get comments: %w", err)
|
|
||||||
}
|
|
||||||
return comments, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Likes is the resolver for the likes field.
|
// Likes is the resolver for the likes field.
|
||||||
func (r *postResolver) Likes(ctx context.Context, obj *domain.Post) ([]*domain.Like, error) {
|
func (r *postResolver) Likes(ctx context.Context, obj *domain.Post) ([]*domain.Like, error) {
|
||||||
likes, err := r.Services.Like.GetByPostID(ctx, obj.ID)
|
likes, err := r.Services.Like.GetByPostID(ctx, obj.ID)
|
||||||
@ -71,6 +62,15 @@ func (r *postResolver) LikesCount(ctx context.Context, obj *domain.Post) (int, e
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CommentsCount is the resolver for the commentsCount field.
|
||||||
|
func (r *postResolver) CommentsCount(ctx context.Context, obj *domain.Post) (int, error) {
|
||||||
|
count, err := r.Services.Comment.GetCountComments(ctx, obj.ID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, fmt.Errorf("failed to get likes count: %w", err)
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
// IsLiked is the resolver for the isLiked field.
|
// IsLiked is the resolver for the isLiked field.
|
||||||
func (r *postResolver) IsLiked(ctx context.Context, obj *domain.Post) (bool, error) {
|
func (r *postResolver) IsLiked(ctx context.Context, obj *domain.Post) (bool, error) {
|
||||||
userID, err := getUserIDFromContext(ctx)
|
userID, err := getUserIDFromContext(ctx)
|
||||||
|
|||||||
@ -15,7 +15,7 @@ type Post {
|
|||||||
title: String! # Заголовок поста
|
title: String! # Заголовок поста
|
||||||
content: String! # Содержание поста
|
content: String! # Содержание поста
|
||||||
author: User! # Автор поста
|
author: User! # Автор поста
|
||||||
comments: [Comment!]! # Комментарии к посту
|
commentsCount: Int!
|
||||||
likes: [Like!]! # Лайки к посту
|
likes: [Like!]! # Лайки к посту
|
||||||
likesCount: Int!
|
likesCount: Int!
|
||||||
isLiked: Boolean!
|
isLiked: Boolean!
|
||||||
|
|||||||
@ -17,6 +17,7 @@ type CommentRepository interface {
|
|||||||
GetByPostID(ctx context.Context, postID int) ([]*domain.Comment, error)
|
GetByPostID(ctx context.Context, postID int) ([]*domain.Comment, error)
|
||||||
Update(ctx context.Context, comment *domain.Comment) error
|
Update(ctx context.Context, comment *domain.Comment) error
|
||||||
Delete(ctx context.Context, id int) error
|
Delete(ctx context.Context, id int) error
|
||||||
|
GetCountComments(ctx context.Context, postID int) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type commentRepository struct {
|
type commentRepository struct {
|
||||||
@ -93,3 +94,19 @@ func (r *commentRepository) GetByPostID(ctx context.Context, postID int) ([]*dom
|
|||||||
|
|
||||||
return comments, nil
|
return comments, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *commentRepository) GetCountComments(ctx context.Context, postID int) (int, error) {
|
||||||
|
query := `
|
||||||
|
SELECT COUNT(*) as comment_count
|
||||||
|
FROM comments
|
||||||
|
WHERE post_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
var count int
|
||||||
|
err := r.db.QueryRowContext(ctx, query, postID).Scan(&count)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ type CommentService interface {
|
|||||||
Create(ctx context.Context, postID, authorID int, content string) (*domain.Comment, error)
|
Create(ctx context.Context, postID, authorID int, content string) (*domain.Comment, error)
|
||||||
GetByID(ctx context.Context, id int) (*domain.Comment, error)
|
GetByID(ctx context.Context, id int) (*domain.Comment, error)
|
||||||
GetByPostID(ctx context.Context, postID int) ([]*domain.Comment, error)
|
GetByPostID(ctx context.Context, postID int) ([]*domain.Comment, error)
|
||||||
|
GetCountComments(ctx context.Context, postID int) (int, error)
|
||||||
Update(ctx context.Context, id int, content string) (*domain.Comment, error)
|
Update(ctx context.Context, id int, content string) (*domain.Comment, error)
|
||||||
Delete(ctx context.Context, id int) error
|
Delete(ctx context.Context, id int) error
|
||||||
}
|
}
|
||||||
@ -126,3 +127,11 @@ func (s *commentService) Update(ctx context.Context, id int, content string) (*d
|
|||||||
func (s *commentService) Delete(ctx context.Context, id int) error {
|
func (s *commentService) Delete(ctx context.Context, id int) error {
|
||||||
return s.commentRepo.Delete(ctx, id)
|
return s.commentRepo.Delete(ctx, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *commentService) GetCountComments(ctx context.Context, postID int) (int, error) {
|
||||||
|
count, err := s.commentRepo.GetCountComments(ctx, postID)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user