- 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 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"]

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

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

@ -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

@ -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 := ""

@ -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)