tercul-backend/internal/adapters/graphql/helpers.go
google-labs-jules[bot] 85f052b2d6 refactor: Align codebase with DDD architecture to fix build
This commit addresses a broken build state caused by a mid-stream architectural refactoring. The changes align the existing code with the new Domain-Driven Design (DDD-lite) structure outlined in `refactor.md`.

Key changes include:
- Defined missing domain interfaces for `Auth`, `Localization`, and `Search`.
- Refactored application services to use a `Commands` and `Queries` pattern.
- Updated GraphQL resolvers to call application services instead of accessing repositories directly.
- Fixed dependency injection in `cmd/api/main.go` by removing the non-existent `ApplicationBuilder` and manually instantiating services.
- Corrected numerous test files (`integration`, `unit`, and `repository` tests) to reflect the new architecture, including fixing mock objects and test suite setups.
- Added missing database migrations for test schemas to resolve "no such table" errors.

This effort successfully gets the application to a compilable state and passes a significant portion of the test suite, laying the groundwork for further development and fixing the remaining test failures.
2025-10-03 01:17:53 +00:00

37 lines
947 B
Go

package graphql
import "context"
// resolveWorkContent uses the Work service to fetch preferred content for a work.
func (r *queryResolver) resolveWorkContent(ctx context.Context, workID uint, preferredLanguage string) *string {
if r.App.Work == nil || r.App.Work.Queries == nil {
return nil
}
work, err := r.App.Work.Queries.GetWorkWithTranslations(ctx, workID)
if err != nil || work == nil {
return nil
}
// Find the translation for the preferred language.
for _, t := range work.Translations {
if t.Language == preferredLanguage && t.Content != "" {
return &t.Content
}
}
// If no specific language match, find the original language content.
for _, t := range work.Translations {
if t.IsOriginalLanguage && t.Content != "" {
return &t.Content
}
}
// Fallback to the work's own description if no suitable translation content is found.
if work.Description != "" {
return &work.Description
}
return nil
}