tercul-backend/internal/adapters/graphql/helpers.go
google-labs-jules[bot] a491f2d538 This commit introduces goose as the database migration tool for the project, replacing the previous gorm.AutoMigrate system. It also includes several code quality improvements identified during the refactoring process.
Key changes include:
- Added `goose` as a project dependency and integrated it into the application's startup logic to automatically apply migrations.
- Created an initial PostgreSQL-compatible migration file containing the full database schema.
- Updated the integration test suite to use the new migration system.
- Refactored authorization logic for collection mutations from the GraphQL resolvers to the application service layer.
- Cleaned up the codebase by removing dead code, unused helper functions, and duplicate struct definitions.
- Fixed several build errors and a logic error in the integration tests.

This change improves the project's production readiness by providing a structured and version-controlled way to manage database schema changes. It also enhances code quality by centralizing business logic and removing technical debt.
2025-10-03 02:52:01 +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
}