tercul-backend/graphql/resolver.go
Damir Mukimov 4957117cb6 Initial commit: Tercul Go project with comprehensive architecture
- Core Go application with GraphQL API using gqlgen
- Comprehensive data models for literary works, authors, translations
- Repository pattern with caching layer
- Authentication and authorization system
- Linguistics analysis capabilities with multiple adapters
- Vector search integration with Weaviate
- Docker containerization support
- Python data migration and analysis scripts
- Clean architecture with proper separation of concerns
- Production-ready configuration and middleware
- Proper .gitignore excluding vendor/, database files, and build artifacts
2025-08-13 07:42:32 +02:00

62 lines
1.2 KiB
Go

package graphql
import (
"context"
"fmt"
"tercul/models"
"tercul/repositories"
)
// Resolver holds repository dependencies.
type Resolver struct {
WorkRepo repositories.WorkRepository
}
// QueryResolver implements Query resolvers.
type QueryResolver struct {
*Resolver
}
func (r *QueryResolver) Work(ctx context.Context, id string) (*models.Work, error) {
var uid uint
_, err := fmt.Sscanf(id, "%d", &uid)
if err != nil {
return nil, err
}
return r.WorkRepo.GetByID(ctx, uid)
}
func (r *QueryResolver) Works(ctx context.Context, filter *struct {
Name *string
Language *string
}, limit *int, offset *int) ([]*models.Work, error) {
// Default pagination values
page := 1
pageSize := 20
if limit != nil {
pageSize = *limit
}
if offset != nil {
page = *offset
}
var paginated *repositories.PaginatedResult[models.Work]
var err error
if filter != nil && filter.Language != nil {
paginated, err = r.WorkRepo.FindByLanguage(ctx, *filter.Language, page, pageSize)
} else {
paginated, err = r.WorkRepo.List(ctx, page, pageSize)
}
if err != nil {
return nil, err
}
result := make([]*models.Work, len(paginated.Items))
for i := range paginated.Items {
result[i] = &paginated.Items[i]
}
return result, nil
}