update after test
This commit is contained in:
parent
7e8e882bfc
commit
ec0e0cde43
@ -43,6 +43,7 @@ func (c *Controller) Register(router fiber.Router) {
|
||||
//router.Patch("/tags", c.UpdateListTags)
|
||||
router.Get("/fields", c.GetFieldsWithPagination)
|
||||
router.Patch("/fields", c.UpdateListCustom)
|
||||
router.Get("/", c.Bitrix)
|
||||
}
|
||||
|
||||
func (c *Controller) Name() string {
|
||||
@ -73,3 +74,8 @@ func (c *WebhookController) Register(router fiber.Router) {
|
||||
func (c *WebhookController) Name() string {
|
||||
return "webhook"
|
||||
}
|
||||
|
||||
// todo check
|
||||
func (c *Controller) Bitrix(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusOK).JSON("OK")
|
||||
}
|
||||
|
@ -1,47 +1,40 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/middleware"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (c *Controller) GetTagsWithPagination(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
req, err := extractParams(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := c.service.GetTagsWithPagination(ctx.Context(), req, accountID)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, pj_errors.ErrNotFound):
|
||||
return ctx.Status(fiber.StatusNotFound).SendString("tags for this user not found")
|
||||
default:
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
}
|
||||
return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
}
|
||||
|
||||
func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
accountID, ok := middleware.GetAccountId(ctx)
|
||||
if !ok {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
//accountID := "654a8909725f47e926f0bebc"
|
||||
|
||||
err := c.service.UpdateListTags(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
}
|
||||
|
||||
return ctx.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
//func (c *Controller) GetTagsWithPagination(ctx *fiber.Ctx) error {
|
||||
// accountID, ok := middleware.GetAccountId(ctx)
|
||||
// if !ok {
|
||||
// return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
// }
|
||||
//
|
||||
// req, err := extractParams(ctx)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// response, err := c.service.GetTagsWithPagination(ctx.Context(), req, accountID)
|
||||
// if err != nil {
|
||||
// switch {
|
||||
// case errors.Is(err, pj_errors.ErrNotFound):
|
||||
// return ctx.Status(fiber.StatusNotFound).SendString("tags for this user not found")
|
||||
// default:
|
||||
// return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
// }
|
||||
// }
|
||||
// return ctx.Status(fiber.StatusOK).JSON(response)
|
||||
//}
|
||||
//
|
||||
//func (c *Controller) UpdateListTags(ctx *fiber.Ctx) error {
|
||||
// accountID, ok := middleware.GetAccountId(ctx)
|
||||
// if !ok {
|
||||
// return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
// }
|
||||
//
|
||||
// //accountID := "654a8909725f47e926f0bebc"
|
||||
//
|
||||
// err := c.service.UpdateListTags(ctx.Context(), accountID)
|
||||
// if err != nil {
|
||||
// return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
||||
// }
|
||||
//
|
||||
// return ctx.SendStatus(fiber.StatusOK)
|
||||
//}
|
||||
|
@ -8,22 +8,22 @@ import (
|
||||
|
||||
// todo config need upd with bitrix data
|
||||
type Config struct {
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"localhost"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"8001"`
|
||||
PostgresCredentials string `env:"PG_CRED" envDefault:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
HTTPHost string `env:"HTTP_HOST" envDefault:"10.8.0.18"`
|
||||
HTTPPort string `env:"HTTP_PORT" envDefault:"1492"`
|
||||
PostgresCredentials string `env:"PG_CRED" envDefault:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
KafkaBrokers string `env:"KAFKA_BROKERS" envDefault:"localhost:9092"`
|
||||
KafkaTopic string `env:"KAFKA_TOPIC" envDefault:"test-topic"`
|
||||
KafkaGroup string `env:"KAFKA_GROUP" envDefault:"bitrixCRM"`
|
||||
RedisAddr string `env:"REDIS_ADDR" envDefault:"localhost:6379"`
|
||||
RedisPassword string `env:"REDIS_PASS" envDefault:"admin"`
|
||||
RedisDB int `env:"REDIS_DB" envDefault:"2"`
|
||||
IntegrationID string `env:"INTEGRATION_ID" envDefault:"2dbd6329-9be6-41f2-aa5f-964b9e723e49"` // код интеграции
|
||||
IntegrationID string `env:"INTEGRATION_ID" envDefault:"app.670bd825e44c52.61826940"` // код интеграции
|
||||
RedirectURL string `env:"REDIRECT_URL" envDefault:"https://squiz.pena.digital/integrations"`
|
||||
// публичный и приватные ключи для енкрипта и декрипта стейта который передаем в битрикс а потом он приходит
|
||||
PublicKey string
|
||||
PrivateKey string
|
||||
PublicKey string `env:"PUBLIC_KEY"`
|
||||
PrivateKey string `env:"PRIVATE_KEY"`
|
||||
// секрет интеграции
|
||||
IntegrationSecret string `env:"INTEGRATION_SECRET" envDefault:"tNK3LwL4ovP0OBK4jKDHJ3646PqRJDOKQYgY6P2t6DCuV8LEzDzszTDY0Fhwmzc8"`
|
||||
IntegrationSecret string `env:"INTEGRATION_SECRET" envDefault:"Ki0MElZXS6dE6tRsGxixri2jmxbxF2Xa4qQpBPziGdAvvLAHJx"`
|
||||
// урл на который будет возвращен пользователь после авторизации это webhook/create get
|
||||
ReturnURL string `env:"RETURN_URL" envDefault:"https://squiz.pena.digital/squiz/amocrm/oauth"`
|
||||
}
|
||||
|
@ -1,36 +1,28 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/pj_errors"
|
||||
)
|
||||
|
||||
func (s *Service) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListTagsResp, error) {
|
||||
response, err := s.repository.BitrixRepo.GetTagsWithPagination(ctx, req, accountID)
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, pj_errors.ErrNotFound
|
||||
}
|
||||
s.logger.Error("error getting tags with pagination", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *Service) UpdateListTags(ctx context.Context, accountID string) error {
|
||||
message := models.KafkaMessage{
|
||||
AccountID: accountID,
|
||||
Type: models.TagsUpdate,
|
||||
}
|
||||
|
||||
err := s.producer.ToKafkaUpdate(ctx, message)
|
||||
if err != nil {
|
||||
s.logger.Error("failed to send message to kafka on service update tags", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
//func (s *Service) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq, accountID string) (*model.UserListTagsResp, error) {
|
||||
// response, err := s.repository.BitrixRepo.GetTagsWithPagination(ctx, req, accountID)
|
||||
// if err != nil {
|
||||
// if err == sql.ErrNoRows {
|
||||
// return nil, pj_errors.ErrNotFound
|
||||
// }
|
||||
// s.logger.Error("error getting tags with pagination", zap.Error(err))
|
||||
// return nil, err
|
||||
// }
|
||||
// return response, nil
|
||||
//}
|
||||
//
|
||||
//func (s *Service) UpdateListTags(ctx context.Context, accountID string) error {
|
||||
// message := models.KafkaMessage{
|
||||
// AccountID: accountID,
|
||||
// Type: models.TagsUpdate,
|
||||
// }
|
||||
//
|
||||
// err := s.producer.ToKafkaUpdate(ctx, message)
|
||||
// if err != nil {
|
||||
// s.logger.Error("failed to send message to kafka on service update tags", zap.Error(err))
|
||||
// return err
|
||||
// }
|
||||
//
|
||||
// return nil
|
||||
//}
|
||||
|
@ -65,7 +65,7 @@ func (s *Service) ConnectAccount(ctx context.Context, accountID string) (*model.
|
||||
|
||||
oauthURL := url.URL{
|
||||
Scheme: "https",
|
||||
Host: "portal.bitrix24.com",
|
||||
Host: "b24-ld76ub.bitrix24.ru", // todo check
|
||||
Path: "/oauth/authorize/",
|
||||
RawQuery: url.Values{
|
||||
"client_id": {s.config.IntegrationID},
|
||||
|
Loading…
Reference in New Issue
Block a user