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
Этот коммит содержится в:
Joram Wilander
2017-01-13 13:53:37 -05:00
коммит произвёл GitHub
родитель 07bad4d6d5
Коммит 97558f6a6e
85 изменённых файлов: 3368 добавлений и 2997 удалений

Просмотреть файл

@@ -6,6 +6,7 @@ import (
"errors"
"github.com/mattermost/platform/api"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
"github.com/spf13/cobra"
@@ -117,6 +118,8 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
team := getTeamFromTeamArg(teamArg)
c := getMockContext()
channel := &model.Channel{
TeamId: team.Id,
Name: name,
@@ -124,10 +127,10 @@ func createChannelCmdF(cmd *cobra.Command, args []string) error {
Header: header,
Purpose: purpose,
Type: channelType,
CreatorId: c.Session.UserId,
}
c := getMockContext()
if _, err := api.CreateChannel(c, channel, false); err != nil {
if _, err := app.CreateChannel(channel, false); err != nil {
return err
}
@@ -197,7 +200,7 @@ func addUserToChannel(channel *model.Channel, user *model.User, userArg string)
CommandPrintErrorln("Can't find user '" + userArg + "'")
return
}
if _, err := api.AddUserToChannel(user, channel); err != nil {
if _, err := app.AddUserToChannel(user, channel); err != nil {
CommandPrintErrorln("Unable to add '" + userArg + "' from " + channel.Name + ". Error: " + err.Error())
}
}
@@ -215,7 +218,7 @@ func deleteChannelsCmdF(cmd *cobra.Command, args []string) error {
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
if result := <-api.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
if result := <-app.Srv.Store.Channel().Delete(channel.Id, model.GetMillis()); result.Err != nil {
CommandPrintErrorln("Unable to delete channel '" + channel.Name + "' error: " + result.Err.Error())
}
}
@@ -240,7 +243,7 @@ func listChannelsCmdF(cmd *cobra.Command, args []string) error {
CommandPrintErrorln("Unable to find team '" + args[i] + "'")
continue
}
if result := <-api.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
if result := <-app.Srv.Store.Channel().GetAll(team.Id); result.Err != nil {
CommandPrintErrorln("Unable to list channels for '" + args[i] + "'")
} else {
channels := result.Data.([]*model.Channel)
@@ -275,7 +278,7 @@ func restoreChannelsCmdF(cmd *cobra.Command, args []string) error {
CommandPrintErrorln("Unable to find channel '" + args[i] + "'")
continue
}
if result := <-api.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
if result := <-app.Srv.Store.Channel().SetDeleteAt(channel.Id, 0, model.GetMillis()); result.Err != nil {
CommandPrintErrorln("Unable to restore channel '" + args[i] + "'")
}
}