mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
Some checks failed
- 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.
67 lines
1.9 KiB
Go
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
|
|
}
|