some debugging

This commit is contained in:
Daniel Goc
2026-03-25 10:42:25 +01:00
parent e279899e49
commit f81eb84499
17 changed files with 70 additions and 67 deletions

View File

@@ -34,7 +34,7 @@ func New() *MeiliService {
}
}
// ==================================== FOR SUPERADMIN ONLY ====================================
// ==================================== FOR TESTING ONLY ====================================
func (s *MeiliService) CreateIndex(id_lang uint) error {
indexName := "meili_products_shop" + strconv.FormatInt(constdata.SHOP_ID, 10) + "_lang" + strconv.FormatInt(int64(id_lang), 10)
@@ -130,7 +130,7 @@ func (s *MeiliService) CreateIndex(id_lang uint) error {
return err
}
// ==================================== FOR DEBUG ONLY ====================================
// ==================================== FOR TESTING ONLY ====================================
func (s *MeiliService) Test(id_lang uint) (meilisearch.SearchResponse, error) {
indexName := "meili_products_shop" + strconv.FormatInt(constdata.SHOP_ID, 10) + "_lang" + strconv.FormatInt(int64(id_lang), 10)

View File

@@ -1,6 +1,7 @@
package menuService
import (
"fmt"
"sort"
"git.ma-al.com/goc_daniel/b2b/app/model"
@@ -27,6 +28,10 @@ func (s *MenuService) GetMenu(id_lang uint) (*model.Category, error) {
return &model.Category{}, err
}
fmt.Printf("all_categories: %v\n", all_categories)
fmt.Printf("id_lang: %v\n", id_lang)
// find the root
root_index := 0
root_found := false

View File

@@ -1,4 +1,4 @@
package productDescriptionService
package productTranslationService
import (
"context"
@@ -26,7 +26,7 @@ import (
googleopt "google.golang.org/api/option"
)
type ProductDescriptionService struct {
type ProductTranslationService struct {
productDescriptionRepo productDescriptionRepo.UIProductDescriptionRepo
ctx context.Context
googleCli translate.TranslationClient
@@ -34,7 +34,7 @@ type ProductDescriptionService struct {
openAIClient openai.Client
}
// New creates a ProductDescriptionService and authenticates against the
// New creates a ProductTranslationService and authenticates against the
// Google Cloud Translation API using a service account key file.
//
// Required configuration (set in .env or environment):
@@ -44,14 +44,14 @@ type ProductDescriptionService struct {
//
// The service account must have the "Cloud Translation API User" role
// (roles/cloudtranslate.user) granted in Google Cloud IAM.
func New() *ProductDescriptionService {
func New() *ProductTranslationService {
ctx := context.Background()
cfg := config.Get()
// Read the service account key file whose path comes from config / env.
data, err := os.ReadFile(cfg.GoogleTranslate.CredentialsFile)
if err != nil {
log.Fatalf("productDescriptionService: cannot read credentials file %q: %v",
log.Fatalf("ProductTranslationService: cannot read credentials file %q: %v",
cfg.GoogleTranslate.CredentialsFile, err)
}
@@ -62,18 +62,18 @@ func New() *ProductDescriptionService {
CredentialsJSON: data,
})
if err != nil {
log.Fatalf("productDescriptionService: cannot build Google credentials: %v", err)
log.Fatalf("ProductTranslationService: cannot build Google credentials: %v", err)
}
googleCli, err := translate.NewTranslationClient(ctx, googleopt.WithAuthCredentials(creds))
if err != nil {
log.Fatalf("productDescriptionService: cannot create Translation client: %v", err)
log.Fatalf("ProductTranslationService: cannot create Translation client: %v", err)
}
openAIClient := openai.NewClient(option.WithAPIKey(os.Getenv("OPENAI_KEY")),
option.WithHTTPClient(&http.Client{Timeout: 300 * time.Second})) // five minutes timeout
return &ProductDescriptionService{
return &ProductTranslationService{
productDescriptionRepo: productDescriptionRepo.New(),
ctx: ctx,
openAIClient: openAIClient,
@@ -82,12 +82,12 @@ func New() *ProductDescriptionService {
}
}
func (s *ProductDescriptionService) GetProductDescription(userID uint, productID uint, productLangID uint) (*model.ProductDescription, error) {
func (s *ProductTranslationService) GetProductDescription(userID uint, productID uint, productLangID uint) (*model.ProductDescription, error) {
return s.productDescriptionRepo.GetProductDescription(productID, productLangID)
}
// Updates relevant fields with the "updates" map
func (s *ProductDescriptionService) SaveProductDescription(userID uint, productID uint, productLangID uint, updates map[string]string) error {
func (s *ProductTranslationService) SaveProductDescription(userID uint, productID uint, productLangID uint, updates map[string]string) error {
// only some fields can be affected
allowedFields := []string{"description", "description_short", "meta_description", "meta_title", "name", "available_now", "available_later", "usage"}
for key := range updates {
@@ -120,7 +120,7 @@ func (s *ProductDescriptionService) SaveProductDescription(userID uint, productI
//
// The Google Cloud project must have the Cloud Translation API enabled and the
// service account must hold the "Cloud Translation API User" role.
func (s *ProductDescriptionService) TranslateProductDescription(userID uint, productID uint, productFromLangID uint, productToLangID uint, aiModel string) (*model.ProductDescription, error) {
func (s *ProductTranslationService) TranslateProductDescription(userID uint, productID uint, productFromLangID uint, productToLangID uint, aiModel string) (*model.ProductDescription, error) {
productDescription, err := s.productDescriptionRepo.GetProductDescription(productID, productFromLangID)
if err != nil {