mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
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.
42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package category
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
)
|
|
|
|
// CategoryQueries contains the query handlers for the category aggregate.
|
|
type CategoryQueries struct {
|
|
repo domain.CategoryRepository
|
|
}
|
|
|
|
// NewCategoryQueries creates a new CategoryQueries handler.
|
|
func NewCategoryQueries(repo domain.CategoryRepository) *CategoryQueries {
|
|
return &CategoryQueries{repo: repo}
|
|
}
|
|
|
|
// Category returns a category by ID.
|
|
func (q *CategoryQueries) Category(ctx context.Context, id uint) (*domain.Category, error) {
|
|
return q.repo.GetByID(ctx, id)
|
|
}
|
|
|
|
// CategoryByName returns a category by name.
|
|
func (q *CategoryQueries) CategoryByName(ctx context.Context, name string) (*domain.Category, error) {
|
|
return q.repo.FindByName(ctx, name)
|
|
}
|
|
|
|
// CategoriesByWorkID returns all categories for a work.
|
|
func (q *CategoryQueries) CategoriesByWorkID(ctx context.Context, workID uint) ([]domain.Category, error) {
|
|
return q.repo.ListByWorkID(ctx, workID)
|
|
}
|
|
|
|
// CategoriesByParentID returns all categories for a parent.
|
|
func (q *CategoryQueries) CategoriesByParentID(ctx context.Context, parentID *uint) ([]domain.Category, error) {
|
|
return q.repo.ListByParentID(ctx, parentID)
|
|
}
|
|
|
|
// Categories returns all categories.
|
|
func (q *CategoryQueries) Categories(ctx context.Context) ([]domain.Category, error) {
|
|
return q.repo.ListAll(ctx)
|
|
}
|