tercul-backend/internal/enrichment/service.go
Damir Mukimov d50722dad5
Some checks failed
Test / Integration Tests (push) Successful in 4s
Build / Build Binary (push) Failing after 2m9s
Docker Build / Build Docker Image (push) Failing after 2m32s
Test / Unit Tests (push) Failing after 3m12s
Lint / Go Lint (push) Failing after 1m0s
Refactor ID handling to use UUIDs across the application
- Updated database models and repositories to replace uint IDs with UUIDs.
- Modified test fixtures to generate and use UUIDs for authors, translations, users, and works.
- Adjusted mock implementations to align with the new UUID structure.
- Ensured all relevant functions and methods are updated to handle UUIDs correctly.
- Added necessary imports for UUID handling in various files.
2025-12-27 00:33:34 +01:00

67 lines
1.9 KiB
Go

package enrichment
import (
"context"
"tercul/internal/domain"
)
// Service is the main entrypoint for the enrichment functionality.
// It orchestrates different enrichers for various domain entities.
type Service struct {
AuthorEnrichers []AuthorEnricher
WorkEnrichers []WorkEnricher
}
// NewService creates a new enrichment Service.
func NewService() *Service {
service := &Service{
AuthorEnrichers: []AuthorEnricher{},
WorkEnrichers: []WorkEnricher{},
}
service.RegisterAuthorEnricher(NewOpenLibraryAuthorEnricher())
return service
}
// AuthorEnricher defines the interface for enriching author data.
type AuthorEnricher interface {
Enrich(ctx context.Context, author *domain.Author) error
Name() string
}
// WorkEnricher defines the interface for enriching work data.
type WorkEnricher interface {
Enrich(ctx context.Context, work *domain.Work) error
Name() string
}
// RegisterAuthorEnricher adds a new author enricher to the service.
func (s *Service) RegisterAuthorEnricher(enricher AuthorEnricher) {
s.AuthorEnrichers = append(s.AuthorEnrichers, enricher)
}
// RegisterWorkEnricher adds a new work enricher to the service.
func (s *Service) RegisterWorkEnricher(enricher WorkEnricher) {
s.WorkEnrichers = append(s.WorkEnrichers, enricher)
}
// EnrichAuthor iterates through registered author enrichers and applies them.
func (s *Service) EnrichAuthor(ctx context.Context, author *domain.Author) error {
for _, enricher := range s.AuthorEnrichers {
if err := enricher.Enrich(ctx, author); err != nil {
// In a real implementation, we might want to log errors but continue.
return err
}
}
return nil
}
// EnrichWork iterates through registered work enrichers and applies them.
func (s *Service) EnrichWork(ctx context.Context, work *domain.Work) error {
for _, enricher := range s.WorkEnrichers {
if err := enricher.Enrich(ctx, work); err != nil {
return err
}
}
return nil
}