Remove FromJSON functions (Part 1) (#17961)
* Remove FromJSON functions (Part 1) ```release-note Removed the following functions: AccessDataFromJson AccessResponseFromJson AnalyticsRowFromJson AnalyticsRowsFromJson AuditFromJson AuditsFromJson AuthDataFromJson AuthorizeRequestFromJson BotFromJson BotPatchFromJson BotListFromJson ``` * fix tests ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
Claudio Costa
родитель
7454680be5
Коммит
e199eba313
23
api4/bot.go
23
api4/bot.go
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -30,8 +31,9 @@ func (api *API) InitBot() {
|
||||
}
|
||||
|
||||
func createBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
botPatch := model.BotPatchFromJson(r.Body)
|
||||
if botPatch == nil {
|
||||
var botPatch *model.BotPatch
|
||||
err := json.NewDecoder(r.Body).Decode(&botPatch)
|
||||
if err != nil {
|
||||
c.SetInvalidParam("bot")
|
||||
return
|
||||
}
|
||||
@@ -62,9 +64,9 @@ func createBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
createdBot, err := c.App.CreateBot(c.AppContext, bot)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
createdBot, appErr := c.App.CreateBot(c.AppContext, bot)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
@@ -82,8 +84,9 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
botUserId := c.Params.BotUserId
|
||||
|
||||
botPatch := model.BotPatchFromJson(r.Body)
|
||||
if botPatch == nil {
|
||||
var botPatch *model.BotPatch
|
||||
err := json.NewDecoder(r.Body).Decode(&botPatch)
|
||||
if err != nil {
|
||||
c.SetInvalidParam("bot")
|
||||
return
|
||||
}
|
||||
@@ -97,9 +100,9 @@ func patchBot(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
updatedBot, err := c.App.PatchBot(botUserId, botPatch)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
updatedBot, appErr := c.App.PatchBot(botUserId, botPatch)
|
||||
if appErr != nil {
|
||||
c.Err = appErr
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package api4
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -444,13 +445,16 @@ func TestPatchBot(t *testing.T) {
|
||||
CheckCreatedStatus(t, resp)
|
||||
defer th.App.PermanentDeleteBot(createdBot.UserId)
|
||||
|
||||
r, err := th.Client.DoApiPut(th.Client.GetBotRoute(createdBot.UserId), `{"creator_id":"`+th.BasicUser2.Id+`"}`)
|
||||
require.Nil(t, err)
|
||||
r, appErr := th.Client.DoApiPut(th.Client.GetBotRoute(createdBot.UserId), `{"creator_id":"`+th.BasicUser2.Id+`"}`)
|
||||
require.Nil(t, appErr)
|
||||
defer func() {
|
||||
_, _ = ioutil.ReadAll(r.Body)
|
||||
_ = r.Body.Close()
|
||||
}()
|
||||
patchedBot := model.BotFromJson(r.Body)
|
||||
var patchedBot *model.Bot
|
||||
err := json.NewDecoder(r.Body).Decode(&patchedBot)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp = model.BuildResponse(r)
|
||||
CheckOKStatus(t, resp)
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user