From fb5e03d888b8a31457264d691269073319c81eaf Mon Sep 17 00:00:00 2001 From: Danil Solovyov Date: Mon, 21 Nov 2022 20:07:49 +0500 Subject: [PATCH] Changes: - little fixes --- Dockerfile | 4 ++-- dal/model/gdisk.go | 2 +- dal/model/yadisk.go | 2 +- handlers/generator.go | 30 +++++++++++++++--------------- handlers/template.go | 29 +++++++++++++++-------------- handlers/yadisk.go | 4 ++-- 6 files changed, 36 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2bb7ec4..bea1a98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,8 +5,8 @@ ADD static static ADD .well-known .well-known ADD tmp tmp ENV DOMAIN=tempgen.pena.digital -ENV YADISK_CLIENT_ID=94482c181e5148c096ae6ad3b2a981ea -ENV YADISK_CLIENT_SECRET=7dc4f541c3f64f4a9078e59d7494d222 +ENV YADISK_CLIENT_ID=1ed4b85c1a5c4e6abf783d3ea28fd947 +ENV YADISK_CLIENT_SECRET=e1d4f385c1274dccb7d29646b802d607 ENV GDISK_CREDENTIALS=./static/gdisk-credentials2.json RUN apk add --no-cache ca-certificates CMD ["/amocrm_templategen_back"] diff --git a/dal/model/gdisk.go b/dal/model/gdisk.go index c00b6aa..84c801a 100644 --- a/dal/model/gdisk.go +++ b/dal/model/gdisk.go @@ -5,7 +5,7 @@ import ( "time" ) -// GDisk (Storage) - хранит информацию о пользователе Google и данных необходимых для хранилища. +// GDisk (StorageType) - хранит информацию о пользователе Google и данных необходимых для хранилища. // Пользователь может иметь несколько хранилищ GDisk. // Email - уникальное поле и закрепляется только за одним пользователем type GDisk struct { diff --git a/dal/model/yadisk.go b/dal/model/yadisk.go index 6ff152e..b2410a2 100644 --- a/dal/model/yadisk.go +++ b/dal/model/yadisk.go @@ -5,7 +5,7 @@ import ( "time" ) -// YaDisk (Storage) - хранит информацию о пользователе Yandex и данных необходимых для хранилища. +// YaDisk (StorageType) - хранит информацию о пользователе Yandex и данных необходимых для хранилища. // Пользователь может иметь несколько хранилищ YaDisk. // Login - уникальное поле и закрепляется только за одним пользователем type YaDisk struct { diff --git a/handlers/generator.go b/handlers/generator.go index a512cc3..db1365f 100644 --- a/handlers/generator.go +++ b/handlers/generator.go @@ -12,10 +12,10 @@ import ( ) type ReqGeneratorByAmoLead struct { - File string `json:"file"` // Путь до файла в Yandex Disk, либо ID файла в Google Disk - StorageID string `json:"storage_id"` - Storage string `json:"storage"` - LeadId int64 `json:"lead_id"` // Required. + File string `json:"file"` // Путь до файла в Yandex Disk, либо ID файла в Google Disk + StorageID string `json:"storage_id"` + StorageType string `json:"storage_type"` + LeadId int64 `json:"lead_id"` // Required. } // GeneratorByAmoLead - сгенерировать файл по lead_id и указанному файлу если он установлен, @@ -96,7 +96,7 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) { var file, storageType, storageID, name string if req.File != "" { - if req.Storage == "" { + if req.StorageType == "" { h.reportError(w, errors.New("storage required"), http.StatusBadRequest) return } @@ -106,7 +106,7 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) { } file = req.File - storageType = req.Storage + storageType = req.StorageType storageID = req.StorageID name = lead.Name } else { @@ -170,12 +170,12 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) { } type ReqGeneratorByData struct { - File string `json:"file"` - StorageID string `json:"storage_id"` - Storage string `json:"storage"` - TemplateID string `json:"template_id"` - Name string `json:"name"` - Data map[string]any `json:"data"` + File string `json:"file"` + StorageID string `json:"storage_id"` + StorageType string `json:"storage_type"` + TemplateID string `json:"template_id"` + Name string `json:"name"` + Data map[string]any `json:"data"` } // GeneratorByData - сгенерировать файл по данным и указанному файлу или шаблону @@ -195,7 +195,7 @@ func (h *Handlers) GeneratorByData(w http.ResponseWriter, r *http.Request) { return } - if req.Storage == "" { + if req.StorageType == "" { h.reportError(w, errors.New("storage required"), http.StatusBadRequest) return } @@ -204,9 +204,9 @@ func (h *Handlers) GeneratorByData(w http.ResponseWriter, r *http.Request) { return } - switch req.Storage { + switch req.StorageType { case "gdisk": - gdiskData, err := h.dal.GDisk.GetByID(r.Context(), req.Storage) + gdiskData, err := h.dal.GDisk.GetByID(r.Context(), req.StorageType) if err != nil { h.reportError(w, err, http.StatusInternalServerError) return diff --git a/handlers/template.go b/handlers/template.go index 5d376c4..bd8bd71 100644 --- a/handlers/template.go +++ b/handlers/template.go @@ -8,12 +8,12 @@ import ( ) type ReqTemplateSet struct { - LeadId int64 `json:"lead_id"` // Required for insert/update - TemplateId string `json:"template_id"` // Required for update - может потом удалить ? - Name string `json:"name"` - File string `json:"file"` // Required. - StorageID string `json:"storage_id"` // Required. id gdisk or yadisk - Storage string `json:"storage"` // Required. yadisk, gdisk - Может удалить потом? + LeadId int64 `json:"lead_id"` // Required for insert/update + TemplateId string `json:"template_id"` // Required for update - может потом удалить ? + Name string `json:"name"` + File string `json:"file"` // Required. + StorageID string `json:"storage_id"` // Required. id gdisk or yadisk + StorageType string `json:"storage_type"` // Required. yadisk, gdisk - Может удалить потом? } type RespTemplateSet struct { @@ -37,7 +37,7 @@ func (h *Handlers) TemplateSet(w http.ResponseWriter, r *http.Request) { return } - if req.Storage == "" || req.StorageID == "" { + if req.StorageType == "" || req.StorageID == "" { h.reportError(w, errors.New("bad request"), http.StatusBadRequest) return } @@ -50,13 +50,14 @@ func (h *Handlers) TemplateSet(w http.ResponseWriter, r *http.Request) { // Search/update template update := &model.Template{ - ID: req.TemplateId, - UserID: amoData.UserID, - LeadId: strconv.FormatInt(req.LeadId, 10), - Name: req.Name, - File: req.File, - StorageID: req.StorageID, - IsDeleted: false, + ID: req.TemplateId, + UserID: amoData.UserID, + LeadId: strconv.FormatInt(req.LeadId, 10), + Name: req.Name, + File: req.File, + StorageID: req.StorageID, + StorageType: req.StorageType, + IsDeleted: false, } templateId := "" diff --git a/handlers/yadisk.go b/handlers/yadisk.go index 093a525..f568ba3 100644 --- a/handlers/yadisk.go +++ b/handlers/yadisk.go @@ -184,7 +184,7 @@ func (h *Handlers) YaDiskGetList(w http.ResponseWriter, r *http.Request) { sendResponse(w, http.StatusOK, yadiskInfo) } -type ReqYaDiskGetResource struct { +type ReqYaDiskGetResources struct { ID string `json:"id"` // ID хранилища Path string `json:"path"` // Путь до папки. По умолчанию: disk:/ Limit int `json:"limit"` // По умолчанию: 20 @@ -192,7 +192,7 @@ type ReqYaDiskGetResource struct { } func (h *Handlers) YaDiskGetResources(w http.ResponseWriter, r *http.Request) { - var req ReqYaDiskGetResource + var req ReqYaDiskGetResources amoData := getAmoByJwt(r)