make GetChannelByName take teamId first (#9134)

* make GetChannelByName take teamId first

I think it is more natural to accept `teamId`, then `channelName`,
given the pattern followed by other Plugin API methods and even the SQL
Store itself. The App layer seems unusual in accepting `channelName`
first.

This also re-generates the mocks fixing the parameter order for the
recently added `UserStatus` APIs.

* add GetChannelByNameForTeamName
Этот коммит содержится в:
Jesse Hallam
2018-07-20 12:03:08 -04:00
коммит произвёл Christopher Speller
родитель 610ac5a53c
Коммит 908a682fcf
5 изменённых файлов: 84 добавлений и 22 удалений

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

@@ -190,10 +190,14 @@ func (api *PluginAPI) GetChannel(channelId string) (*model.Channel, *model.AppEr
return api.app.GetChannel(channelId) return api.app.GetChannel(channelId)
} }
func (api *PluginAPI) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) { func (api *PluginAPI) GetChannelByName(teamId, name string) (*model.Channel, *model.AppError) {
return api.app.GetChannelByName(name, teamId) return api.app.GetChannelByName(name, teamId)
} }
func (api *PluginAPI) GetChannelByNameForTeamName(teamName, channelName string) (*model.Channel, *model.AppError) {
return api.app.GetChannelByNameForTeamName(channelName, teamName)
}
func (api *PluginAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) { func (api *PluginAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) {
return api.app.GetDirectChannel(userId1, userId2) return api.app.GetDirectChannel(userId1, userId2)
} }

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

@@ -101,14 +101,17 @@ type API interface {
// DeleteChannel deletes a channel. // DeleteChannel deletes a channel.
DeleteChannel(channelId string) *model.AppError DeleteChannel(channelId string) *model.AppError
// GetChannels gets a list of all channels. // GetPublicChannelsForTeam gets a list of all channels.
GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError) GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError)
// GetChannel gets a channel. // GetChannel gets a channel.
GetChannel(channelId string) (*model.Channel, *model.AppError) GetChannel(channelId string) (*model.Channel, *model.AppError)
// GetChannelByName gets a channel by its name. // GetChannelByName gets a channel by its name, given a team id.
GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) GetChannelByName(teamId, name string) (*model.Channel, *model.AppError)
// GetChannelByNameForTeamName gets a channel by its name, given a team name.
GetChannelByNameForTeamName(teamName, channelName string) (*model.Channel, *model.AppError)
// GetDirectChannel gets a direct message channel. // GetDirectChannel gets a direct message channel.
GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError)
@@ -149,13 +152,13 @@ type API interface {
// UpdatePost updates a post. // UpdatePost updates a post.
UpdatePost(post *model.Post) (*model.Post, *model.AppError) UpdatePost(post *model.Post) (*model.Post, *model.AppError)
// Set will store a key-value pair, unique per plugin. // KVSet will store a key-value pair, unique per plugin.
KVSet(key string, value []byte) *model.AppError KVSet(key string, value []byte) *model.AppError
// Get will retrieve a value based on the key. Returns nil for non-existent keys. // KVGet will retrieve a value based on the key. Returns nil for non-existent keys.
KVGet(key string) ([]byte, *model.AppError) KVGet(key string) ([]byte, *model.AppError)
// Delete will remove a key-value pair. Returns nil for non-existent keys. // KVDelete will remove a key-value pair. Returns nil for non-existent keys.
KVDelete(key string) *model.AppError KVDelete(key string) *model.AppError
// PublishWebSocketEvent sends an event to WebSocket connections. // PublishWebSocketEvent sends an event to WebSocket connections.

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

@@ -1286,8 +1286,8 @@ type Z_GetChannelByNameReturns struct {
B *model.AppError B *model.AppError
} }
func (g *apiRPCClient) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) { func (g *apiRPCClient) GetChannelByName(teamId, name string) (*model.Channel, *model.AppError) {
_args := &Z_GetChannelByNameArgs{name, teamId} _args := &Z_GetChannelByNameArgs{teamId, name}
_returns := &Z_GetChannelByNameReturns{} _returns := &Z_GetChannelByNameReturns{}
if err := g.client.Call("Plugin.GetChannelByName", _args, _returns); err != nil { if err := g.client.Call("Plugin.GetChannelByName", _args, _returns); err != nil {
g.log.Error("RPC call to GetChannelByName API failed.", mlog.Err(err)) g.log.Error("RPC call to GetChannelByName API failed.", mlog.Err(err))
@@ -1297,7 +1297,7 @@ func (g *apiRPCClient) GetChannelByName(name, teamId string) (*model.Channel, *m
func (s *apiRPCServer) GetChannelByName(args *Z_GetChannelByNameArgs, returns *Z_GetChannelByNameReturns) error { func (s *apiRPCServer) GetChannelByName(args *Z_GetChannelByNameArgs, returns *Z_GetChannelByNameReturns) error {
if hook, ok := s.impl.(interface { if hook, ok := s.impl.(interface {
GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) GetChannelByName(teamId, name string) (*model.Channel, *model.AppError)
}); ok { }); ok {
returns.A, returns.B = hook.GetChannelByName(args.A, args.B) returns.A, returns.B = hook.GetChannelByName(args.A, args.B)
} else { } else {
@@ -1306,6 +1306,36 @@ func (s *apiRPCServer) GetChannelByName(args *Z_GetChannelByNameArgs, returns *Z
return nil return nil
} }
type Z_GetChannelByNameForTeamNameArgs struct {
A string
B string
}
type Z_GetChannelByNameForTeamNameReturns struct {
A *model.Channel
B *model.AppError
}
func (g *apiRPCClient) GetChannelByNameForTeamName(teamName, channelName string) (*model.Channel, *model.AppError) {
_args := &Z_GetChannelByNameForTeamNameArgs{teamName, channelName}
_returns := &Z_GetChannelByNameForTeamNameReturns{}
if err := g.client.Call("Plugin.GetChannelByNameForTeamName", _args, _returns); err != nil {
g.log.Error("RPC call to GetChannelByNameForTeamName API failed.", mlog.Err(err))
}
return _returns.A, _returns.B
}
func (s *apiRPCServer) GetChannelByNameForTeamName(args *Z_GetChannelByNameForTeamNameArgs, returns *Z_GetChannelByNameForTeamNameReturns) error {
if hook, ok := s.impl.(interface {
GetChannelByNameForTeamName(teamName, channelName string) (*model.Channel, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetChannelByNameForTeamName(args.A, args.B)
} else {
return fmt.Errorf("API GetChannelByNameForTeamName called but not implemented.")
}
return nil
}
type Z_GetDirectChannelArgs struct { type Z_GetDirectChannelArgs struct {
A string A string
B string B string

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

@@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0 // Code generated by mockery v1.0.0. DO NOT EDIT.
// Regenerate this file using `make plugin-mocks`. // Regenerate this file using `make plugin-mocks`.
@@ -308,13 +308,13 @@ func (_m *API) GetChannel(channelId string) (*model.Channel, *model.AppError) {
return r0, r1 return r0, r1
} }
// GetChannelByName provides a mock function with given fields: name, teamId // GetChannelByName provides a mock function with given fields: teamId, name
func (_m *API) GetChannelByName(name string, teamId string) (*model.Channel, *model.AppError) { func (_m *API) GetChannelByName(teamId string, name string) (*model.Channel, *model.AppError) {
ret := _m.Called(name, teamId) ret := _m.Called(teamId, name)
var r0 *model.Channel var r0 *model.Channel
if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok { if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok {
r0 = rf(name, teamId) r0 = rf(teamId, name)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Channel) r0 = ret.Get(0).(*model.Channel)
@@ -323,7 +323,32 @@ func (_m *API) GetChannelByName(name string, teamId string) (*model.Channel, *mo
var r1 *model.AppError var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
r1 = rf(name, teamId) r1 = rf(teamId, name)
} else {
if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError)
}
}
return r0, r1
}
// GetChannelByNameForTeamName provides a mock function with given fields: teamName, channelName
func (_m *API) GetChannelByNameForTeamName(teamName string, channelName string) (*model.Channel, *model.AppError) {
ret := _m.Called(teamName, channelName)
var r0 *model.Channel
if rf, ok := ret.Get(0).(func(string, string) *model.Channel); ok {
r0 = rf(teamName, channelName)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Channel)
}
}
var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
r1 = rf(teamName, channelName)
} else { } else {
if ret.Get(1) != nil { if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError) r1 = ret.Get(1).(*model.AppError)
@@ -1067,13 +1092,13 @@ func (_m *API) UpdateUser(user *model.User) (*model.User, *model.AppError) {
return r0, r1 return r0, r1
} }
// UpdateUserStatus provides a mock function with given fields: status, userId // UpdateUserStatus provides a mock function with given fields: userId, status
func (_m *API) UpdateUserStatus(status string, userId string) (*model.Status, *model.AppError) { func (_m *API) UpdateUserStatus(userId string, status string) (*model.Status, *model.AppError) {
ret := _m.Called(status, userId) ret := _m.Called(userId, status)
var r0 *model.Status var r0 *model.Status
if rf, ok := ret.Get(0).(func(string, string) *model.Status); ok { if rf, ok := ret.Get(0).(func(string, string) *model.Status); ok {
r0 = rf(status, userId) r0 = rf(userId, status)
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.Status) r0 = ret.Get(0).(*model.Status)
@@ -1082,7 +1107,7 @@ func (_m *API) UpdateUserStatus(status string, userId string) (*model.Status, *m
var r1 *model.AppError var r1 *model.AppError
if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok {
r1 = rf(status, userId) r1 = rf(userId, status)
} else { } else {
if ret.Get(1) != nil { if ret.Get(1) != nil {
r1 = ret.Get(1).(*model.AppError) r1 = ret.Get(1).(*model.AppError)

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

@@ -1,4 +1,4 @@
// Code generated by mockery v1.0.0 // Code generated by mockery v1.0.0. DO NOT EDIT.
// Regenerate this file using `make plugin-mocks`. // Regenerate this file using `make plugin-mocks`.