diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-01-13 13:53:37 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-13 13:53:37 -0500 |
commit | 97558f6a6ec4c53fa69035fb430ead209d9c222d (patch) | |
tree | 6fc57f5b75b15a025348c6e295cea6aedb9e69ae /api/command.go | |
parent | 07bad4d6d518a9012a20fec8309cd625f57c7a8c (diff) | |
download | chat-97558f6a6ec4c53fa69035fb430ead209d9c222d.tar.gz chat-97558f6a6ec4c53fa69035fb430ead209d9c222d.tar.bz2 chat-97558f6a6ec4c53fa69035fb430ead209d9c222d.zip |
PLT-4938 Add app package and move logic over from api package (#4931)
* Add app package and move logic over from api package
* Change app package functions to return errors
* Move non-api tests into app package
* Fix merge
Diffstat (limited to 'api/command.go')
-rw-r--r-- | api/command.go | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/api/command.go b/api/command.go index 9c8f60be5..8a1126bf3 100644 --- a/api/command.go +++ b/api/command.go @@ -13,6 +13,7 @@ import ( l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -69,7 +70,7 @@ func listCommands(c *Context, w http.ResponseWriter, r *http.Request) { } if *utils.Cfg.ServiceSettings.EnableCommands { - if result := <-Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { + if result := <-app.Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { c.Err = result.Err return } else { @@ -119,11 +120,11 @@ func executeCommand(c *Context, w http.ResponseWriter, r *http.Request) { return } - chanChan := Srv.Store.Channel().Get(commandArgs.ChannelId, true) - teamChan := Srv.Store.Team().Get(c.TeamId) - userChan := Srv.Store.User().Get(c.Session.UserId) + chanChan := app.Srv.Store.Channel().Get(commandArgs.ChannelId, true) + teamChan := app.Srv.Store.Team().Get(c.TeamId) + userChan := app.Srv.Store.User().Get(c.Session.UserId) - if result := <-Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { + if result := <-app.Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { c.Err = result.Err return } else { @@ -221,6 +222,7 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe post.ChannelId = commandArgs.ChannelId post.RootId = commandArgs.RootId post.ParentId = commandArgs.ParentId + post.UserId = c.Session.UserId if !builtIn { post.AddProp("from_webhook", "true") @@ -246,7 +248,9 @@ func handleResponse(c *Context, w http.ResponseWriter, response *model.CommandRe } } - CreateCommandPost(c, post, response) + if _, err := app.CreateCommandPost(post, c.TeamId, response); err != nil { + l4g.Error(err.Error()) + } w.Write([]byte(response.ToJson())) } @@ -277,7 +281,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) { cmd.CreatorId = c.Session.UserId cmd.TeamId = c.TeamId - if result := <-Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { + if result := <-app.Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { c.Err = result.Err return } else { @@ -297,7 +301,7 @@ func createCommand(c *Context, w http.ResponseWriter, r *http.Request) { } } - if result := <-Srv.Store.Command().Save(cmd); result.Err != nil { + if result := <-app.Srv.Store.Command().Save(cmd); result.Err != nil { c.Err = result.Err return } else { @@ -332,7 +336,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) { cmd.Trigger = strings.ToLower(cmd.Trigger) var oldCmd *model.Command - if result := <-Srv.Store.Command().Get(cmd.Id); result.Err != nil { + if result := <-app.Srv.Store.Command().Get(cmd.Id); result.Err != nil { c.Err = result.Err return } else { @@ -358,7 +362,7 @@ func updateCommand(c *Context, w http.ResponseWriter, r *http.Request) { cmd.TeamId = oldCmd.TeamId } - if result := <-Srv.Store.Command().Update(cmd); result.Err != nil { + if result := <-app.Srv.Store.Command().Update(cmd); result.Err != nil { c.Err = result.Err return } else { @@ -379,7 +383,7 @@ func listTeamCommands(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { + if result := <-app.Srv.Store.Command().GetByTeam(c.TeamId); result.Err != nil { c.Err = result.Err return } else { @@ -412,7 +416,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) { } var cmd *model.Command - if result := <-Srv.Store.Command().Get(id); result.Err != nil { + if result := <-app.Srv.Store.Command().Get(id); result.Err != nil { c.Err = result.Err return } else { @@ -427,7 +431,7 @@ func regenCommandToken(c *Context, w http.ResponseWriter, r *http.Request) { cmd.Token = model.NewId() - if result := <-Srv.Store.Command().Update(cmd); result.Err != nil { + if result := <-app.Srv.Store.Command().Update(cmd); result.Err != nil { c.Err = result.Err return } else { @@ -458,7 +462,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) { return } - if result := <-Srv.Store.Command().Get(id); result.Err != nil { + if result := <-app.Srv.Store.Command().Get(id); result.Err != nil { c.Err = result.Err return } else { @@ -469,7 +473,7 @@ func deleteCommand(c *Context, w http.ResponseWriter, r *http.Request) { } } - if err := (<-Srv.Store.Command().Delete(id, model.GetMillis())).Err; err != nil { + if err := (<-app.Srv.Store.Command().Delete(id, model.GetMillis())).Err; err != nil { c.Err = err return } |