mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit isolates the `Work` aggregate into its own package at `internal/domain/work`, following the first step of the refactoring plan in `refactor.md`. - The `Work` struct, related types, and the `WorkRepository` interface have been moved to the new package. - A circular dependency between `domain` and `work` was resolved by moving the `AnalyticsRepository` to the `app` layer. - All references to the moved types have been updated across the entire codebase to fix compilation errors. - Test files, including mocks and integration tests, have been updated to reflect the new structure.
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"tercul/internal/app/localization"
|
|
"tercul/internal/domain/work"
|
|
"tercul/internal/platform/log"
|
|
"tercul/internal/platform/search"
|
|
)
|
|
|
|
// IndexService pushes localized snapshots into Weaviate for search
|
|
type IndexService interface {
|
|
IndexWork(ctx context.Context, work work.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 work.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) }
|