mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
Key changes include: - Moved authorization logic for collection mutations from the GraphQL resolvers to the application service layer, ensuring that ownership checks are handled consistently within the business logic. - Updated the `collection` command handlers and input structs to accept a user ID for authorization. - Removed orphaned code, including unused resolver definitions (`workResolver`, `translationResolver`) and misplaced helper functions from `schema.resolvers.go`. - Re-implemented the `Stats` resolvers for the `Work` and `Translation` types, ensuring they correctly call the `analytics` application service. - Fixed several build errors related to type mismatches and redeclared functions by regenerating the GraphQL code and correcting helper function signatures. - Updated integration tests to provide authenticated user context for collection mutations, ensuring that the new authorization checks pass.
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
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
|
|
}
|
|
|
|
func toInt32(i int64) *int32 {
|
|
val := int32(i)
|
|
return &val
|
|
}
|
|
|
|
func toInt(i int) *int {
|
|
return &i
|
|
}
|