mirror of
https://github.com/SamyRai/tercul-backend.git
synced 2025-12-27 05:11:34 +00:00
This commit includes the following changes: - Refactored all data repositories in `internal/data/sql/` to use a consistent `sql` package and to align with the new `domain` models. - Fixed the GraphQL structure by moving the server creation logic from `internal/app` to `cmd/api`, which resolved an import cycle. - Corrected numerous incorrect import paths for packages like `graph`, `linguistics`, `syncjob`, and the legacy `models` package. - Resolved several package and function redeclaration errors. - Removed legacy migration code.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package search
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"tercul/internal/domain"
|
|
"tercul/internal/platform/config"
|
|
"time"
|
|
|
|
"github.com/weaviate/weaviate-go-client/v5/weaviate"
|
|
)
|
|
|
|
var Client *weaviate.Client
|
|
|
|
func InitWeaviate() {
|
|
var err error
|
|
Client, err = weaviate.NewClient(weaviate.Config{
|
|
Scheme: "http",
|
|
Host: config.Cfg.WeaviateHost,
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("Failed to connect to Weaviate: %v", err)
|
|
}
|
|
|
|
log.Println("Connected to Weaviate successfully.")
|
|
}
|
|
|
|
// UpsertWork inserts or updates a Work object in Weaviate
|
|
func UpsertWork(work domain.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
|
|
}
|