mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This change introduces a service layer to encapsulate the business logic for each domain aggregate. This will make the code more modular, testable, and easier to maintain. The following services have been created: - author - bookmark - category - collection - comment - like - tag - translation - user The main Application struct has been updated to use these new services. The integration test suite has also been updated to use the new Application struct and services. This is a work in progress. The next step is to fix the compilation errors and then refactor the resolvers to use the new services.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"tercul/internal/app/localization"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/platform/log"
|
|
"tercul/internal/platform/search"
|
|
)
|
|
|
|
// IndexService pushes localized snapshots into Weaviate for search
|
|
type IndexService interface {
|
|
IndexWork(ctx context.Context, work domain.Work) error
|
|
}
|
|
|
|
type indexService struct {
|
|
localization *localization.Service
|
|
weaviate search.WeaviateWrapper
|
|
}
|
|
|
|
func NewIndexService(localization *localization.Service, weaviate search.WeaviateWrapper) IndexService {
|
|
return &indexService{localization: localization, weaviate: weaviate}
|
|
}
|
|
|
|
func (s *indexService) IndexWork(ctx context.Context, work domain.Work) error {
|
|
log.LogDebug("Indexing work", log.F("work_id", work.ID))
|
|
// TODO: Get content from translation service
|
|
content := ""
|
|
// Choose best content snapshot for indexing
|
|
// content, err := s.localization.GetWorkContent(ctx, work.ID, work.Language)
|
|
// if err != nil {
|
|
// log.LogError("Failed to get work content for indexing", log.F("work_id", work.ID), log.F("error", err))
|
|
// return err
|
|
// }
|
|
|
|
err := s.weaviate.IndexWork(ctx, &work, content)
|
|
if err != nil {
|
|
log.LogError("Failed to index work in Weaviate", log.F("work_id", work.ID), log.F("error", err))
|
|
return err
|
|
}
|
|
log.LogInfo("Successfully indexed work", log.F("work_id", work.ID))
|
|
return nil
|
|
}
|
|
|
|
func formatID(id uint) string { return fmt.Sprintf("%d", id) }
|