tercul-backend/internal/app/author/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

35 lines
843 B
Go

package author
import (
"context"
"tercul/internal/domain"
)
// AuthorQueries contains the query handlers for the author aggregate.
type AuthorQueries struct {
repo domain.AuthorRepository
}
// NewAuthorQueries creates a new AuthorQueries handler.
func NewAuthorQueries(repo domain.AuthorRepository) *AuthorQueries {
return &AuthorQueries{repo: repo}
}
// Author returns an author by ID.
func (q *AuthorQueries) Author(ctx context.Context, id uint) (*domain.Author, error) {
return q.repo.GetByID(ctx, id)
}
// Authors returns all authors.
func (q *AuthorQueries) Authors(ctx context.Context) ([]*domain.Author, error) {
authors, err := q.repo.ListAll(ctx)
if err != nil {
return nil, err
}
authorPtrs := make([]*domain.Author, len(authors))
for i := range authors {
authorPtrs[i] = &authors[i]
}
return authorPtrs, nil
}