tercul-backend/internal/platform/search/weaviate_wrapper.go
google-labs-jules[bot] 06e6e2be85 refactor(domain): Isolate Work aggregate
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.
2025-10-03 16:15:09 +00:00

45 lines
1004 B
Go

package search
import (
"context"
"fmt"
"tercul/internal/domain/work"
"time"
"github.com/weaviate/weaviate-go-client/v5/weaviate"
)
type WeaviateWrapper interface {
IndexWork(ctx context.Context, work *work.Work, content string) error
}
type weaviateWrapper struct {
client *weaviate.Client
}
func NewWeaviateWrapper(client *weaviate.Client) WeaviateWrapper {
return &weaviateWrapper{client: client}
}
func (w *weaviateWrapper) IndexWork(ctx context.Context, work *work.Work, content string) error {
properties := map[string]interface{}{
"language": work.Language,
"title": work.Title,
"description": work.Description,
"status": work.Status,
"createdAt": work.CreatedAt.Format(time.RFC3339),
"updatedAt": work.UpdatedAt.Format(time.RFC3339),
}
if content != "" {
properties["content"] = content
}
_, err := w.client.Data().Creator().
WithClassName("Work").
WithID(fmt.Sprintf("%d", work.ID)).
WithProperties(properties).
Do(ctx)
return err
}