- little fixes
This commit is contained in:
Danil Solovyov 2022-11-21 20:07:49 +05:00
parent 7fb2ba976b
commit fb5e03d888
6 changed files with 36 additions and 35 deletions

@ -5,8 +5,8 @@ ADD static static
ADD .well-known .well-known ADD .well-known .well-known
ADD tmp tmp ADD tmp tmp
ENV DOMAIN=tempgen.pena.digital ENV DOMAIN=tempgen.pena.digital
ENV YADISK_CLIENT_ID=94482c181e5148c096ae6ad3b2a981ea ENV YADISK_CLIENT_ID=1ed4b85c1a5c4e6abf783d3ea28fd947
ENV YADISK_CLIENT_SECRET=7dc4f541c3f64f4a9078e59d7494d222 ENV YADISK_CLIENT_SECRET=e1d4f385c1274dccb7d29646b802d607
ENV GDISK_CREDENTIALS=./static/gdisk-credentials2.json ENV GDISK_CREDENTIALS=./static/gdisk-credentials2.json
RUN apk add --no-cache ca-certificates RUN apk add --no-cache ca-certificates
CMD ["/amocrm_templategen_back"] CMD ["/amocrm_templategen_back"]

@ -5,7 +5,7 @@ import (
"time" "time"
) )
// GDisk (Storage) - хранит информацию о пользователе Google и данных необходимых для хранилища. // GDisk (StorageType) - хранит информацию о пользователе Google и данных необходимых для хранилища.
// Пользователь может иметь несколько хранилищ GDisk. // Пользователь может иметь несколько хранилищ GDisk.
// Email - уникальное поле и закрепляется только за одним пользователем // Email - уникальное поле и закрепляется только за одним пользователем
type GDisk struct { type GDisk struct {

@ -5,7 +5,7 @@ import (
"time" "time"
) )
// YaDisk (Storage) - хранит информацию о пользователе Yandex и данных необходимых для хранилища. // YaDisk (StorageType) - хранит информацию о пользователе Yandex и данных необходимых для хранилища.
// Пользователь может иметь несколько хранилищ YaDisk. // Пользователь может иметь несколько хранилищ YaDisk.
// Login - уникальное поле и закрепляется только за одним пользователем // Login - уникальное поле и закрепляется только за одним пользователем
type YaDisk struct { type YaDisk struct {

@ -12,10 +12,10 @@ import (
) )
type ReqGeneratorByAmoLead struct { type ReqGeneratorByAmoLead struct {
File string `json:"file"` // Путь до файла в Yandex Disk, либо ID файла в Google Disk File string `json:"file"` // Путь до файла в Yandex Disk, либо ID файла в Google Disk
StorageID string `json:"storage_id"` StorageID string `json:"storage_id"`
Storage string `json:"storage"` StorageType string `json:"storage_type"`
LeadId int64 `json:"lead_id"` // Required. LeadId int64 `json:"lead_id"` // Required.
} }
// GeneratorByAmoLead - сгенерировать файл по lead_id и указанному файлу если он установлен, // GeneratorByAmoLead - сгенерировать файл по lead_id и указанному файлу если он установлен,
@ -96,7 +96,7 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) {
var file, storageType, storageID, name string var file, storageType, storageID, name string
if req.File != "" { if req.File != "" {
if req.Storage == "" { if req.StorageType == "" {
h.reportError(w, errors.New("storage required"), http.StatusBadRequest) h.reportError(w, errors.New("storage required"), http.StatusBadRequest)
return return
} }
@ -106,7 +106,7 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) {
} }
file = req.File file = req.File
storageType = req.Storage storageType = req.StorageType
storageID = req.StorageID storageID = req.StorageID
name = lead.Name name = lead.Name
} else { } else {
@ -170,12 +170,12 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) {
} }
type ReqGeneratorByData struct { type ReqGeneratorByData struct {
File string `json:"file"` File string `json:"file"`
StorageID string `json:"storage_id"` StorageID string `json:"storage_id"`
Storage string `json:"storage"` StorageType string `json:"storage_type"`
TemplateID string `json:"template_id"` TemplateID string `json:"template_id"`
Name string `json:"name"` Name string `json:"name"`
Data map[string]any `json:"data"` Data map[string]any `json:"data"`
} }
// GeneratorByData - сгенерировать файл по данным и указанному файлу или шаблону // GeneratorByData - сгенерировать файл по данным и указанному файлу или шаблону
@ -195,7 +195,7 @@ func (h *Handlers) GeneratorByData(w http.ResponseWriter, r *http.Request) {
return return
} }
if req.Storage == "" { if req.StorageType == "" {
h.reportError(w, errors.New("storage required"), http.StatusBadRequest) h.reportError(w, errors.New("storage required"), http.StatusBadRequest)
return return
} }
@ -204,9 +204,9 @@ func (h *Handlers) GeneratorByData(w http.ResponseWriter, r *http.Request) {
return return
} }
switch req.Storage { switch req.StorageType {
case "gdisk": 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 { if err != nil {
h.reportError(w, err, http.StatusInternalServerError) h.reportError(w, err, http.StatusInternalServerError)
return return

@ -8,12 +8,12 @@ import (
) )
type ReqTemplateSet struct { type ReqTemplateSet struct {
LeadId int64 `json:"lead_id"` // Required for insert/update LeadId int64 `json:"lead_id"` // Required for insert/update
TemplateId string `json:"template_id"` // Required for update - может потом удалить ? TemplateId string `json:"template_id"` // Required for update - может потом удалить ?
Name string `json:"name"` Name string `json:"name"`
File string `json:"file"` // Required. File string `json:"file"` // Required.
StorageID string `json:"storage_id"` // Required. id gdisk or yadisk StorageID string `json:"storage_id"` // Required. id gdisk or yadisk
Storage string `json:"storage"` // Required. yadisk, gdisk - Может удалить потом? StorageType string `json:"storage_type"` // Required. yadisk, gdisk - Может удалить потом?
} }
type RespTemplateSet struct { type RespTemplateSet struct {
@ -37,7 +37,7 @@ func (h *Handlers) TemplateSet(w http.ResponseWriter, r *http.Request) {
return return
} }
if req.Storage == "" || req.StorageID == "" { if req.StorageType == "" || req.StorageID == "" {
h.reportError(w, errors.New("bad request"), http.StatusBadRequest) h.reportError(w, errors.New("bad request"), http.StatusBadRequest)
return return
} }
@ -50,13 +50,14 @@ func (h *Handlers) TemplateSet(w http.ResponseWriter, r *http.Request) {
// Search/update template // Search/update template
update := &model.Template{ update := &model.Template{
ID: req.TemplateId, ID: req.TemplateId,
UserID: amoData.UserID, UserID: amoData.UserID,
LeadId: strconv.FormatInt(req.LeadId, 10), LeadId: strconv.FormatInt(req.LeadId, 10),
Name: req.Name, Name: req.Name,
File: req.File, File: req.File,
StorageID: req.StorageID, StorageID: req.StorageID,
IsDeleted: false, StorageType: req.StorageType,
IsDeleted: false,
} }
templateId := "" templateId := ""

@ -184,7 +184,7 @@ func (h *Handlers) YaDiskGetList(w http.ResponseWriter, r *http.Request) {
sendResponse(w, http.StatusOK, yadiskInfo) sendResponse(w, http.StatusOK, yadiskInfo)
} }
type ReqYaDiskGetResource struct { type ReqYaDiskGetResources struct {
ID string `json:"id"` // ID хранилища ID string `json:"id"` // ID хранилища
Path string `json:"path"` // Путь до папки. По умолчанию: disk:/ Path string `json:"path"` // Путь до папки. По умолчанию: disk:/
Limit int `json:"limit"` // По умолчанию: 20 Limit int `json:"limit"` // По умолчанию: 20
@ -192,7 +192,7 @@ type ReqYaDiskGetResource struct {
} }
func (h *Handlers) YaDiskGetResources(w http.ResponseWriter, r *http.Request) { func (h *Handlers) YaDiskGetResources(w http.ResponseWriter, r *http.Request) {
var req ReqYaDiskGetResource var req ReqYaDiskGetResources
amoData := getAmoByJwt(r) amoData := getAmoByJwt(r)