From 7d3df1ae95709ae50ac48b3fdb821dd4f308fa15 Mon Sep 17 00:00:00 2001 From: Danil Solovyov Date: Mon, 21 Nov 2022 21:59:50 +0500 Subject: [PATCH] =?UTF-8?q?Changes:=20=20=20-=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=20=D1=81=D1=82=D0=B0=D1=82=D1=83=D1=81=20200?= =?UTF-8?q?=20=D0=BD=D0=B0=20500=20=D0=B2=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA?= =?UTF-8?q?=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/amo.go | 9 +++++++++ handlers/generator.go | 10 +++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/handlers/amo.go b/handlers/amo.go index 21099ed..c375d31 100644 --- a/handlers/amo.go +++ b/handlers/amo.go @@ -21,6 +21,7 @@ type ReqAmoSaveToken struct { State string `json:"state" schema:"state"` FromWidget string `json:"from_widget" schema:"from_widget"` Referer string `json:"referer" schema:"referer"` + Platform string `json:"platform" schema:"platform"` // Вообще без понятия что это } func (h *Handlers) AmoSaveToken(w http.ResponseWriter, r *http.Request) { @@ -106,6 +107,7 @@ type RespAmoState struct { GenCount int `json:"gen_count"` AuthYandexUrl string `json:"auth_yandex_url"` AuthGoogleUrl string `json:"auth_google_url"` + AuthAmoUrl string `json:"auth_amo_url"` Storages map[string]interface{} `json:"storages"` Visibility []int64 `json:"visibility"` Creation []int64 `json:"creation"` @@ -153,10 +155,17 @@ func (h *Handlers) AmoState(w http.ResponseWriter, r *http.Request, redirectUrn return } + authAmoUrl, err := h.Amo.GenerateOAuthUrl(amoData.UserID, redirectUri) + if err != nil { + h.reportError(w, err, http.StatusInternalServerError) + return + } + resp := RespAmoState{ GenCount: 97, AuthYandexUrl: authYandexUrl, AuthGoogleUrl: authGoogleUrl, + AuthAmoUrl: authAmoUrl, Storages: storages, Visibility: amoData.AccessRules.Visibility, Creation: amoData.AccessRules.Creation, diff --git a/handlers/generator.go b/handlers/generator.go index db1365f..8c23ddd 100644 --- a/handlers/generator.go +++ b/handlers/generator.go @@ -53,7 +53,7 @@ func (h *Handlers) GeneratorByAmoLead(w http.ResponseWriter, r *http.Request) { lead, err := amoClient.GetLeadById(leadId) if err != nil { - h.reportError(w, err, 200) + h.reportError(w, err, http.StatusInternalServerError) return } @@ -252,13 +252,13 @@ func (h *Handlers) GeneratorByAmoWebhook(w http.ResponseWriter, r *http.Request) reqBody, err := io.ReadAll(r.Body) if err != nil { - h.reportError(w, err, 200) + h.reportError(w, err, http.StatusBadRequest) return } p, err := url.ParseQuery(string(reqBody)) if err != nil { - h.reportError(w, err, 200) + h.reportError(w, err, http.StatusBadRequest) return } @@ -269,7 +269,7 @@ func (h *Handlers) GeneratorByAmoWebhook(w http.ResponseWriter, r *http.Request) // Запрашиваем данные по аккаунту amoData, err := h.dal.Amo.GetByAccountID(r.Context(), accId) if err != nil { - h.reportError(w, err, 200) + h.reportError(w, err, http.StatusInternalServerError) return } @@ -282,7 +282,7 @@ func (h *Handlers) GeneratorByAmoWebhook(w http.ResponseWriter, r *http.Request) lead, err := amoClient.GetLeadById(leadId) if err != nil { - h.reportError(w, err, 200) + h.reportError(w, err, http.StatusInternalServerError) return }