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.
39 lines
962 B
Go
39 lines
962 B
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"tercul/internal/domain/work"
|
|
"time"
|
|
|
|
"github.com/weaviate/weaviate-go-client/v5/weaviate"
|
|
)
|
|
|
|
var Client *weaviate.Client
|
|
|
|
// UpsertWork inserts or updates a Work object in Weaviate
|
|
func UpsertWork(client *weaviate.Client, work work.Work) error {
|
|
// Create a properties map with the fields that exist in the Work model
|
|
properties := map[string]interface{}{
|
|
"language": work.Language,
|
|
"title": work.Title,
|
|
"description": work.Description,
|
|
"status": work.Status,
|
|
// Add timestamps
|
|
"createdAt": work.CreatedAt.Format(time.RFC3339),
|
|
"updatedAt": work.UpdatedAt.Format(time.RFC3339),
|
|
}
|
|
|
|
_, err := client.Data().Creator().
|
|
WithClassName("Work").
|
|
WithID(fmt.Sprintf("%d", work.ID)). // Use the ID from the Work model
|
|
WithProperties(properties).
|
|
Do(context.Background())
|
|
|
|
if err != nil {
|
|
log.Printf("Weaviate Upsert Error for Work ID %d: %v", work.ID, err)
|
|
}
|
|
return err
|
|
}
|