mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
Some checks failed
- Updated database models and repositories to replace uint IDs with UUIDs. - Modified test fixtures to generate and use UUIDs for authors, translations, users, and works. - Adjusted mock implementations to align with the new UUID structure. - Ensured all relevant functions and methods are updated to handle UUIDs correctly. - Added necessary imports for UUID handling in various files.
44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package category
|
|
|
|
import (
|
|
"context"
|
|
"tercul/internal/domain"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
// 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 uuid.UUID) (*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 uuid.UUID) ([]domain.Category, error) {
|
|
return q.repo.ListByWorkID(ctx, workID)
|
|
}
|
|
|
|
// CategoriesByParentID returns all categories for a parent.
|
|
func (q *CategoryQueries) CategoriesByParentID(ctx context.Context, parentID *uuid.UUID) ([]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)
|
|
}
|