init new amo repo methods

This commit is contained in:
Pavel 2024-04-18 14:00:02 +03:00
parent 8fea5d95c3
commit 105a18f646
6 changed files with 180 additions and 28 deletions

@ -703,7 +703,7 @@ WITH user_data AS (
WHERE users.AccountID = $1
)
INSERT INTO tags (amoID, accountID, Entity, name, color, createdAt)
SELECT (new_tags->>'Amoid')::INT,
SELECT (new_tags->>'AmoID')::INT,
user_data.AmoID,
CAST(new_tags->>'Entity' AS entitytype),
new_tags->>'Name',

@ -220,7 +220,7 @@ WITH user_data AS (
WHERE users.AccountID = $1
)
INSERT INTO tags (amoID, accountID, Entity, name, color, createdAt)
SELECT (new_tags->>'Amoid')::INT,
SELECT (new_tags->>'AmoID')::INT,
user_data.AmoID,
CAST(new_tags->>'Entity' AS entitytype),
new_tags->>'Name',

@ -44,11 +44,11 @@ type Token struct {
type Pipeline struct {
// айдишник в нашей системе Primary Key
ID int `json:"ID"`
ID int64 `json:"ID"`
/* - айдишник воронки в амо*/
Amoid int `json:"AmoID"`
Amoid int32 `json:"AmoID"`
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
AccountID int `json:"AccountID"`
AccountID int32 `json:"AccountID"`
/* - название воронки в амо*/
Name string `json:"Name"`
/* - флаг архивной воронки в амо*/
@ -61,13 +61,13 @@ type Pipeline struct {
type Step struct {
/* - айдишник в нашей системе Primary Key*/
ID int `json:"ID"`
ID int64 `json:"ID"`
/* - айдишник шага воронки в амо*/
Amoid int `json:"AmoID"`
Amoid int32 `json:"AmoID"`
/* - айдишник воронки в амо*/
Pipelineid int `json:"PipelineID"`
Pipelineid int32 `json:"PipelineID"`
/* - связь с аккаунтом в интеграции амо id в амо*/
Accountid int `json:"AccountID"`
Accountid int32 `json:"AccountID"`
/* - название воронки в амо*/
Name string `json:"Name"`
/* - цвет шага в амо*/
@ -80,11 +80,11 @@ type Step struct {
type Tag struct {
/* - айдишник в нашей системе Primary Key*/
ID int `json:"ID"`
ID int64 `json:"ID"`
/* - айдишник тега в амо*/
Amoid int `json:"AmoID"`
Amoid int32 `json:"AmoID"`
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
Accountid int `json:"AccountID"`
Accountid int32 `json:"AccountID"`
/* - сущность, к которой принадлежит этот тег. Наверное, стоит сделать через enum в базе*/
Entity EntityType `json:"Entity"`
/* - название тега в амо*/
@ -99,13 +99,13 @@ type Tag struct {
type Field struct {
/* - айдишник в нашей системе Primary Key*/
ID int `json:"ID"`
ID int64 `json:"ID"`
/* - айдишник кастомного поля в амо*/
Amoid int `json:"AmoID"`
Amoid int32 `json:"AmoID"`
/* - кодовое слово в амо*/
Code string `json:"Code"`
/* - связь с аккаунтом в интеграции амо id аккаунта в амо*/
Accountid int `json:"AccountID"`
Accountid int32 `json:"AccountID"`
/* - название воронки в амо*/
Name string `json:"Name"`
/* - тип сущности в амо, для которой это кастомное поле*/

@ -9,7 +9,7 @@ type PaginationReq struct {
/* - указание страницы пагинации. Если страница не указана, применять 0*/
Page int `json:"page"`
/* - указание размера страницы пагинации. По умолчанию применять 25*/
Size int `json:"size"`
Size int32 `json:"size"`
}
type RulesReq struct {

@ -38,14 +38,14 @@ type ListSavedIDUTMResp struct {
type UserListFieldsResp struct {
/* - общее количество кастомных полей, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список кастомных полей, которые были закешированы нашим сервисом*/
Items []Field `json:"items"`
}
type UserListPipelinesResp struct {
/* - общее количество воронок, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
/* - список воронок, которые были закешированы нашим сервисом*/
Items []Pipeline `json:"items"`
}
@ -61,7 +61,7 @@ type UserListStepsResp struct {
/* - список шагов воронок, которые были закешированы нашим сервисом*/
Items []Step `json:"items"`
/* - общее количество шагов воронок, которые у нас закешированы для этого пользователя*/
Count int `json:"count"`
Count int64 `json:"count"`
}
type UserListTagsResp struct {

@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"encoding/json"
"fmt"
"github.com/sqlc-dev/pqtype"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal/sqlcgen"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
@ -39,7 +40,7 @@ func (r *AmoRepository) UpdateListUsers(ctx context.Context) error {
func (r *AmoRepository) GettingUserWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListResp, error) {
rows, err := r.queries.GetUsersWithPagination(ctx, sqlcgen.GetUsersWithPaginationParams{
Column1: req.Page,
Limit: int32(req.Size),
Limit: req.Size,
})
if err != nil {
@ -266,8 +267,36 @@ func (r *AmoRepository) UpdateListPipelines(ctx context.Context) error {
}
func (r *AmoRepository) GettingPipelinesFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListPipelinesResp, error) {
return nil, nil
func (r *AmoRepository) GetPipelinesWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListPipelinesResp, error) {
rows, err := r.queries.GetPipelinesWithPagination(ctx, sqlcgen.GetPipelinesWithPaginationParams{
Column1: req.Page,
Limit: req.Size,
})
if err != nil {
return nil, err
}
var count int64
var pipelines []model.Pipeline
for _, row := range rows {
count = row.TotalCount
pipeline := model.Pipeline{
ID: row.ID,
Amoid: row.Amoid,
AccountID: row.Accountid,
Name: row.Name,
Isarchive: row.Isarchive,
Createdat: row.Createdat.Time.Unix(),
}
pipelines = append(pipelines, pipeline)
}
resp := model.UserListPipelinesResp{
Count: count,
Items: pipelines,
}
return &resp, nil
}
func (r *AmoRepository) CheckPipelines(ctx context.Context, accountID string, pipelines []model.Pipeline) error {
@ -288,8 +317,38 @@ func (r *AmoRepository) InsertPipeline(ctx context.Context, pipeline *model.Pipe
// методы steps
func (r *AmoRepository) GettingStepsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListStepsResp, error) {
return nil, nil
func (r *AmoRepository) GetStepsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListStepsResp, error) {
rows, err := r.queries.GetStepsWithPagination(ctx, sqlcgen.GetStepsWithPaginationParams{
Column1: req.Page,
Limit: req.Size,
})
if err != nil {
return nil, err
}
var count int64
var steps []model.Step
for _, row := range rows {
count = row.TotalCount
step := model.Step{
ID: row.ID,
Amoid: row.Amoid,
Pipelineid: row.Pipelineid,
Accountid: row.Accountid,
Name: row.Name,
Color: row.Color,
Createdat: row.Createdat.Time.Unix(),
}
steps = append(steps, step)
}
resp := model.UserListStepsResp{
Count: count,
Items: steps,
}
return &resp, nil
}
func (r *AmoRepository) UpdateListSteps(ctx context.Context) error {
@ -318,8 +377,45 @@ func (r *AmoRepository) InsertStep(ctx context.Context, step *model.Step) error
// методы tags
func (r *AmoRepository) GettingTagsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListTagsResp, error) {
return nil, nil
func (r *AmoRepository) GetTagsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListTagsResp, error) {
rows, err := r.queries.GetTagsWithPagination(ctx, sqlcgen.GetTagsWithPaginationParams{
Column1: req.Page,
Limit: req.Size,
})
if err != nil {
return nil, err
}
var count int64
var tags []model.Tag
for _, row := range rows {
count = row.TotalCount
var entity model.EntityType
if v, ok := row.Entity.(string); ok {
entity = model.EntityType(v)
} else {
fmt.Println("unexpected type for EntityType:", row.Entity)
}
tag := model.Tag{
ID: row.ID,
Amoid: row.Amoid,
Accountid: row.Accountid,
Entity: entity,
Name: row.Name,
Color: &row.Color,
Createdat: row.Createdat.Time.Unix(),
}
tags = append(tags, tag)
}
resp := model.UserListTagsResp{
Count: count,
Items: tags,
}
return &resp, nil
}
func (r *AmoRepository) UpdateListTags(ctx context.Context) error {
@ -330,7 +426,23 @@ func (r *AmoRepository) UpdateListTags(ctx context.Context) error {
}
func (r *AmoRepository) CheckTags(ctx context.Context, tags []model.Tag, tokenID string) error {
var column2 []json.RawMessage
for _, tag := range tags {
jsonTag, err := json.Marshal(tag)
if err != nil {
return err
}
column2 = append(column2, jsonTag)
}
_, err := r.queries.CheckTags(ctx, sqlcgen.CheckTagsParams{
Accountid: tokenID,
Column2: column2,
})
if err != nil {
return err
}
return nil
}
@ -348,8 +460,48 @@ func (r *AmoRepository) InsertTag(ctx context.Context, tag *model.Tag) error {
// методы fields
func (r *AmoRepository) GettingFieldsFromCash(ctx context.Context, req *model.PaginationReq) (*model.UserListFieldsResp, error) {
return nil, nil
func (r *AmoRepository) GetFieldsWithPagination(ctx context.Context, req *model.PaginationReq) (*model.UserListFieldsResp, error) {
rows, err := r.queries.GetFieldsWithPagination(ctx, sqlcgen.GetFieldsWithPaginationParams{
Column1: req.Page,
Limit: req.Size,
})
if err != nil {
return nil, err
}
var count int64
var fields []model.Field
for _, row := range rows {
count = row.TotalCount
var entity model.EntityType
if v, ok := row.Entity.(string); ok {
entity = model.EntityType(v)
} else {
fmt.Println("unexpected type for EntityType:", row.Entity)
}
field := model.Field{
ID: row.ID,
Amoid: row.Amoid,
Code: row.Code,
Accountid: row.Accountid,
Name: row.Name,
Entity: entity,
Type: row.Type,
Createdat: row.Createdat.Time.Unix(),
}
fields = append(fields, field)
}
resp := model.UserListFieldsResp{
Count: count,
Items: fields,
}
return &resp, nil
}
func (r *AmoRepository) UpdateListCustom(ctx context.Context) error {