add logic for saving created deals in db
This commit is contained in:
parent
e7a06144ae
commit
c9caa9b947
3
go.mod
3
go.mod
@ -12,7 +12,7 @@ require (
|
||||
github.com/twmb/franz-go v1.16.1
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240505074742-07895eccdd07
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506103401-eb032d19f851
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
)
|
||||
|
||||
@ -30,7 +30,6 @@ require (
|
||||
github.com/klauspost/compress v1.17.6 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/kyokomi/emoji v2.2.4+incompatible // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||
|
10
go.sum
10
go.sum
@ -58,8 +58,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kyokomi/emoji v2.2.4+incompatible h1:np0woGKwx9LiHAQmwZx79Oc0rHpNw3o+3evou4BEPv4=
|
||||
github.com/kyokomi/emoji v2.2.4+incompatible/go.mod h1:mZ6aGCD7yk8j6QY6KICwnZ2pxoszVseX1DNoGtU2tBA=
|
||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
@ -153,7 +151,11 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
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/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240505074742-07895eccdd07 h1:ttTQdCfoOj5L/C6xv9GEVDd23LWGkvgZCCEXvSXzjEo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240505074742-07895eccdd07/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506085405-7aabcb97f64d h1:qYFFofXrJUyM6vEYqHj5+Wt8a01XJZK8qY4COgyfmKA=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506085405-7aabcb97f64d/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506100156-7877cdcdc2d7 h1:VLk+lPzRNg7ai8IoapmoHnK4xrvLgi6ugWKeoDJc+v4=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506100156-7877cdcdc2d7/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506103401-eb032d19f851 h1:BaYvqxcwJuwVD0GQpyCtmArewJ3s1yggCic/FDnYOog=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240506103401-eb032d19f851/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/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||
|
@ -63,7 +63,7 @@ type Source struct {
|
||||
}
|
||||
|
||||
type DealResp struct {
|
||||
DealID int `json:"id"` // ID сделки
|
||||
DealID int32 `json:"id"` // ID сделки
|
||||
ContactID int `json:"contact_id"` // ID контакта
|
||||
CompanyID int `json:"company_id"` // ID компании
|
||||
Merged bool `json:"merged"` // Флаг, который показывает, найден дубль подходящий под условия поиска дублей и произведено объединение или нет
|
||||
|
@ -8,7 +8,9 @@ import (
|
||||
"fmt"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/amo"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -93,10 +95,38 @@ func (wc *PostFields) startFetching(ctx context.Context) {
|
||||
if err != nil {
|
||||
wc.logger.Error("error creating deal in amo", zap.Error(err))
|
||||
}
|
||||
fmt.Println(resp)
|
||||
err = wc.saveDealToDB(ctx, resp, accessToken, err)
|
||||
if err != nil {
|
||||
wc.logger.Error("error saving resp data to db", zap.Error(err))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (wc *PostFields) Stop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wc *PostFields) saveDealToDB(ctx context.Context, resp []models.DealResp, accessToken string, errResp error) error {
|
||||
status := "success"
|
||||
if errResp != nil {
|
||||
status = errResp.Error()
|
||||
}
|
||||
for _, dealResp := range resp {
|
||||
requestID := strings.Join(dealResp.RequestID, ",")
|
||||
answerID, err := strconv.ParseInt(requestID, 10, 64)
|
||||
if err != nil {
|
||||
wc.logger.Error("error converting str requestID to int answerID", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(answerID)
|
||||
|
||||
err = wc.amoRepo.AmoRepo.SaveDealStatus(ctx, amo.SaveDealDeps{DealID: dealResp.DealID, AnswerID: answerID, AccessToken: accessToken, Status: status})
|
||||
if err != nil {
|
||||
wc.logger.Error("error saving deal status to database", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -367,12 +367,22 @@ func (m *Methods) CheckUTMs(ctx context.Context, token, accountID string, ids []
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fields, err := m.repo.AmoRepo.GetUserFieldsByID(ctx, utms[0].Accountid)
|
||||
user, err := m.repo.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting user data by account id in check utms wc method", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fields, err := m.repo.AmoRepo.GetUserFieldsByID(ctx, user.AmoID)
|
||||
if err != nil {
|
||||
m.logger.Error("error getting user fields by amo account id", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(utms) < 0 {
|
||||
return fields, err
|
||||
}
|
||||
|
||||
toCreated, toUpdate := tools.ToCreatedUpdate(utms, fields)
|
||||
|
||||
if len(toUpdate) > 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user