tercul-backend/internal/app/translation/queries.go
google-labs-jules[bot] fa90dd79da feat: Complete large-scale refactor and prepare for production
This commit marks the completion of a major refactoring effort to stabilize the codebase, improve its structure, and prepare it for production.

The key changes include:

- **Domain Layer Consolidation:** The `Work` entity and its related types, along with all other domain entities and repository interfaces, have been consolidated into the main `internal/domain` package. This eliminates import cycles and provides a single, coherent source of truth for the domain model.

- **Data Access Layer Refactoring:** The repository implementations in `internal/data/sql` have been updated to align with the new domain layer. The `BaseRepositoryImpl` has been corrected to use pointer receivers, and all concrete repositories now correctly embed it, ensuring consistent and correct behavior.

- **Application Layer Stabilization:** All application services in `internal/app` have been updated to use the new domain types and repository interfaces. Dependency injection has been corrected throughout the application, ensuring that all services are initialized with the correct dependencies.

- **GraphQL Adapter Fixes:** The GraphQL resolver implementation in `internal/adapters/graphql` has been updated to correctly handle the new domain types and service methods. The auto-generated GraphQL code has been regenerated to ensure it is in sync with the schema and runtime.

- **Test Suite Overhaul:** All test suites have been fixed to correctly implement their respective interfaces and use the updated domain model. Mock repositories and test suites have been corrected to properly embed the `testify` base types, resolving numerous build and linter errors.

- **Dependency Management:** The Go modules have been tidied, and the module cache has been cleaned to ensure a consistent and correct dependency graph.

- **Code Quality and Verification:** The entire codebase now passes all builds, tests, and linter checks, ensuring a high level of quality and stability.

This comprehensive effort has resulted in a more robust, maintainable, and production-ready application.
2025-10-07 11:09:37 +00:00

73 lines
2.7 KiB
Go

package translation
import (
"context"
"tercul/internal/domain"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/trace"
)
// TranslationQueries contains the query handlers for the translation aggregate.
type TranslationQueries struct {
repo domain.TranslationRepository
tracer trace.Tracer
}
// NewTranslationQueries creates a new TranslationQueries handler.
func NewTranslationQueries(repo domain.TranslationRepository) *TranslationQueries {
return &TranslationQueries{
repo: repo,
tracer: otel.Tracer("translation.queries"),
}
}
// Translation returns a translation by ID.
func (q *TranslationQueries) Translation(ctx context.Context, id uint) (*domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "Translation")
defer span.End()
return q.repo.GetByID(ctx, id)
}
// TranslationsByWorkID returns all translations for a work.
func (q *TranslationQueries) TranslationsByWorkID(ctx context.Context, workID uint) ([]domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "TranslationsByWorkID")
defer span.End()
return q.repo.ListByWorkID(ctx, workID)
}
// TranslationsByEntity returns all translations for an entity.
func (q *TranslationQueries) TranslationsByEntity(ctx context.Context, entityType string, entityID uint) ([]domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "TranslationsByEntity")
defer span.End()
return q.repo.ListByEntity(ctx, entityType, entityID)
}
// TranslationsByTranslatorID returns all translations for a translator.
func (q *TranslationQueries) TranslationsByTranslatorID(ctx context.Context, translatorID uint) ([]domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "TranslationsByTranslatorID")
defer span.End()
return q.repo.ListByTranslatorID(ctx, translatorID)
}
// TranslationsByStatus returns all translations for a status.
func (q *TranslationQueries) TranslationsByStatus(ctx context.Context, status domain.TranslationStatus) ([]domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "TranslationsByStatus")
defer span.End()
return q.repo.ListByStatus(ctx, status)
}
// Translations returns all translations.
func (q *TranslationQueries) Translations(ctx context.Context) ([]domain.Translation, error) {
ctx, span := q.tracer.Start(ctx, "Translations")
defer span.End()
return q.repo.ListAll(ctx)
}
// ListTranslations returns a paginated list of translations for a work, with optional language filtering.
func (q *TranslationQueries) ListTranslations(ctx context.Context, workID uint, language *string, page, pageSize int) (*domain.PaginatedResult[domain.Translation], error) {
ctx, span := q.tracer.Start(ctx, "ListTranslations")
defer span.End()
return q.repo.ListByWorkIDPaginated(ctx, workID, language, page, pageSize)
}