fix after bug catching

This commit is contained in:
Pavel 2024-04-30 01:36:49 +03:00
parent eb70c134bf
commit cf4ae8e9ba
7 changed files with 33 additions and 19 deletions

2
go.mod

@ -11,7 +11,7 @@ require (
github.com/twmb/franz-go v1.16.1 github.com/twmb/franz-go v1.16.1
go.uber.org/zap v1.27.0 go.uber.org/zap v1.27.0
google.golang.org/protobuf v1.33.0 google.golang.org/protobuf v1.33.0
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429140348-c5336475b2b9 penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429222907-77355a3a328a
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
) )

4
go.sum

@ -151,7 +151,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6 h1:oV+/HNX+JPoQ3/GUx08hio7d45WpY0AMGrFs7j70QlA=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM= penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429140348-c5336475b2b9 h1:2Nchy6DOWIdgqK+FAmhjJqNCUYTwDa35+MUA0eiyEsg= penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429222907-77355a3a328a h1:57a/l9iivs4hqtASSQt7ldOAXLmdJvw5N3sxY7Q+/jw=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429140348-c5336475b2b9/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64= penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240429222907-77355a3a328a/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo= penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I= penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=

@ -52,6 +52,9 @@ func (c *Controller) SetQuizSettings(ctx *fiber.Ctx) error {
return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int") return ctx.Status(fiber.StatusBadRequest).SendString("failed convert quizID to int")
} }
//accountID := "64f2cd7a7047f28fdabf6d9e"
//quizIDInt := 1
var request model.RulesReq var request model.RulesReq
if err := ctx.BodyParser(&request); err != nil { if err := ctx.BodyParser(&request); err != nil {
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"}) return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})

@ -5,27 +5,26 @@ import (
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
) )
func ToCreatedUpdate(utms []model.CheckUserUtm) ([]models.AddLeadsFields, []int32) { func ToCreatedUpdate(utms []model.UTM, fields []model.Field) ([]models.AddLeadsFields, []int32) {
var toCreated []models.AddLeadsFields var toCreated []models.AddLeadsFields
var toUpdate []int32 var toUpdate []int32
for _, utm := range utms { for _, utm := range utms {
if utm.Status == false { matched := false
to := models.AddLeadsFields{ for _, field := range fields {
Type: model.TypeAmoText, if utm.Name == field.Name {
Name: utm.Name, toUpdate = append(toUpdate, int32(utm.ID))
matched = true
break
} }
toCreated = append(toCreated, to)
} }
if utm.Status == true { if !matched {
toUpdate = append(toUpdate, int32(utm.ID)) toCreated = append(toCreated, models.AddLeadsFields{Type: model.TypeAmoText, Name: utm.Name})
} }
} }
return toCreated, toUpdate return toCreated, toUpdate
} }
func MatchingUTMs(utms []model.CheckUserUtm, fields []models.CustomField) []model.UTM { func MatchingUTMs(utms []model.UTM, fields []models.CustomField) []model.UTM {
var forUpdate []model.UTM var forUpdate []model.UTM
for _, utm := range utms { for _, utm := range utms {
for _, field := range fields { for _, field := range fields {

@ -205,7 +205,7 @@ func (wc *QueueUpdater) processMessages(ctx context.Context, message models.Kafk
return err return err
} }
err = wc.methods.CheckUTMs(ctx, token.AccessToken, message.Rule.Utms) err = wc.methods.CheckUTMs(ctx, token.AccessToken, message.AccountID, message.Rule.Utms)
if err != nil { if err != nil {
wc.logger.Error("error check user utms and add fields or update in amo or db", zap.Error(err)) wc.logger.Error("error check user utms and add fields or update in amo or db", zap.Error(err))
return err return err

@ -394,14 +394,20 @@ func (m *Methods) CreateUserFromWebHook(ctx context.Context, accountID string, a
}, nil }, nil
} }
func (m *Methods) CheckUTMs(ctx context.Context, token string, ids []int32) error { func (m *Methods) CheckUTMs(ctx context.Context, token, accountID string, ids []int32) error {
utms, err := m.repo.AmoRepo.CheckUserUtms(ctx, ids) utms, err := m.repo.AmoRepo.GetUtmsByID(ctx, ids)
if err != nil { if err != nil {
m.logger.Error("error getting user UTM byList IDs", zap.Error(err)) m.logger.Error("error getting user UTM byList IDs", zap.Error(err))
return err return err
} }
toCreated, toUpdate := tools.ToCreatedUpdate(utms) fields, err := m.repo.AmoRepo.GetUserFieldsByID(ctx, utms[0].Accountid)
if err != nil {
m.logger.Error("error getting user fields by amo account id", zap.Error(err))
return err
}
toCreated, toUpdate := tools.ToCreatedUpdate(utms, fields)
if len(toUpdate) > 0 { if len(toUpdate) > 0 {
err = m.repo.AmoRepo.UpdateUtmsFields(ctx, toUpdate) err = m.repo.AmoRepo.UpdateUtmsFields(ctx, toUpdate)
@ -418,6 +424,12 @@ func (m *Methods) CheckUTMs(ctx context.Context, token string, ids []int32) erro
return err return err
} }
err = m.repo.AmoRepo.CheckFields(ctx, tools.ToField(createdFields.Embedded.CustomFields, model.LeadsType), accountID)
if err != nil {
m.logger.Error("error created amo fields in db", zap.Error(err))
return err
}
forUpdate := tools.MatchingUTMs(utms, createdFields.Embedded.CustomFields) forUpdate := tools.MatchingUTMs(utms, createdFields.Embedded.CustomFields)
err = m.repo.AmoRepo.UpdateUTMs(ctx, forUpdate) err = m.repo.AmoRepo.UpdateUTMs(ctx, forUpdate)
if err != nil { if err != nil {

@ -741,7 +741,7 @@ func Test_UTM(t *testing.T) {
ids = append(ids, int32(id)) ids = append(ids, int32(id))
} }
resp, err := repo.AmoRepo.CheckUserUtms(ctx, ids) resp, err := repo.AmoRepo.GetUtmsByID(ctx, ids)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }