tercul-backend/internal/app/translation/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.7 KiB
Go

package translation
import (
"context"
"tercul/internal/domain"
)
// TranslationQueries contains the query handlers for the translation aggregate.
type TranslationQueries struct {
repo domain.TranslationRepository
}
// NewTranslationQueries creates a new TranslationQueries handler.
func NewTranslationQueries(repo domain.TranslationRepository) *TranslationQueries {
return &TranslationQueries{repo: repo}
}
// Translation returns a translation by ID.
func (q *TranslationQueries) Translation(ctx context.Context, id uint) (*domain.Translation, error) {
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) {
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) {
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) {
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) {
return q.repo.ListByStatus(ctx, status)
}
// Translations returns all translations.
func (q *TranslationQueries) Translations(ctx context.Context) ([]domain.Translation, error) {
return q.repo.ListAll(ctx)
}