tercul-backend/internal/app/comment/queries.go
google-labs-jules[bot] 1c4dcbcf99 Refactor: Introduce service layer for application logic
This change introduces a service layer to encapsulate the business logic
for each domain aggregate. This will make the code more modular,
testable, and easier to maintain.

The following services have been created:
- author
- bookmark
- category
- collection
- comment
- like
- tag
- translation
- user

The main Application struct has been updated to use these new services.
The integration test suite has also been updated to use the new
Application struct and services.

This is a work in progress. The next step is to fix the compilation
errors and then refactor the resolvers to use the new services.
2025-09-09 02:28:25 +00:00

47 lines
1.5 KiB
Go

package comment
import (
"context"
"tercul/internal/domain"
)
// CommentQueries contains the query handlers for the comment aggregate.
type CommentQueries struct {
repo domain.CommentRepository
}
// NewCommentQueries creates a new CommentQueries handler.
func NewCommentQueries(repo domain.CommentRepository) *CommentQueries {
return &CommentQueries{repo: repo}
}
// Comment returns a comment by ID.
func (q *CommentQueries) Comment(ctx context.Context, id uint) (*domain.Comment, error) {
return q.repo.GetByID(ctx, id)
}
// CommentsByUserID returns all comments for a user.
func (q *CommentQueries) CommentsByUserID(ctx context.Context, userID uint) ([]domain.Comment, error) {
return q.repo.ListByUserID(ctx, userID)
}
// CommentsByWorkID returns all comments for a work.
func (q *CommentQueries) CommentsByWorkID(ctx context.Context, workID uint) ([]domain.Comment, error) {
return q.repo.ListByWorkID(ctx, workID)
}
// CommentsByTranslationID returns all comments for a translation.
func (q *CommentQueries) CommentsByTranslationID(ctx context.Context, translationID uint) ([]domain.Comment, error) {
return q.repo.ListByTranslationID(ctx, translationID)
}
// CommentsByParentID returns all comments for a parent.
func (q *CommentQueries) CommentsByParentID(ctx context.Context, parentID uint) ([]domain.Comment, error) {
return q.repo.ListByParentID(ctx, parentID)
}
// Comments returns all comments.
func (q *CommentQueries) Comments(ctx context.Context) ([]domain.Comment, error) {
return q.repo.ListAll(ctx)
}