diff options
author | Chris <ccbrown112@gmail.com> | 2017-09-21 14:00:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-21 14:00:14 -0500 |
commit | e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d (patch) | |
tree | e46d2dcd0dcad346da8641f4bd62f9134bc80699 /plugin/rpcplugin/api.go | |
parent | 266ff8670244da288aec937320d9eecc7996af35 (diff) | |
download | chat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.tar.gz chat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.tar.bz2 chat-e525383c52b0c65ad3b3f6cdbee73f56e1e3f67d.zip |
plugin CRUD operations for users, posts, channels, and teams (#7479)
Diffstat (limited to 'plugin/rpcplugin/api.go')
-rw-r--r-- | plugin/rpcplugin/api.go | 326 |
1 files changed, 321 insertions, 5 deletions
diff --git a/plugin/rpcplugin/api.go b/plugin/rpcplugin/api.go index 29ed95258..4195a4f86 100644 --- a/plugin/rpcplugin/api.go +++ b/plugin/rpcplugin/api.go @@ -28,11 +28,40 @@ func (api *LocalAPI) LoadPluginConfiguration(args struct{}, reply *[]byte) error return nil } +type APIErrorReply struct { + Error *model.AppError +} + type APITeamReply struct { Team *model.Team Error *model.AppError } +func (api *LocalAPI) CreateTeam(args *model.Team, reply *APITeamReply) error { + team, err := api.api.CreateTeam(args) + *reply = APITeamReply{ + Team: team, + Error: err, + } + return nil +} + +func (api *LocalAPI) DeleteTeam(args string, reply *APIErrorReply) error { + *reply = APIErrorReply{ + Error: api.api.DeleteTeam(args), + } + return nil +} + +func (api *LocalAPI) GetTeam(args string, reply *APITeamReply) error { + team, err := api.api.GetTeam(args) + *reply = APITeamReply{ + Team: team, + Error: err, + } + return nil +} + func (api *LocalAPI) GetTeamByName(args string, reply *APITeamReply) error { team, err := api.api.GetTeamByName(args) *reply = APITeamReply{ @@ -42,11 +71,54 @@ func (api *LocalAPI) GetTeamByName(args string, reply *APITeamReply) error { return nil } +func (api *LocalAPI) UpdateTeam(args *model.Team, reply *APITeamReply) error { + team, err := api.api.UpdateTeam(args) + *reply = APITeamReply{ + Team: team, + Error: err, + } + return nil +} + type APIUserReply struct { User *model.User Error *model.AppError } +func (api *LocalAPI) CreateUser(args *model.User, reply *APIUserReply) error { + user, err := api.api.CreateUser(args) + *reply = APIUserReply{ + User: user, + Error: err, + } + return nil +} + +func (api *LocalAPI) DeleteUser(args string, reply *APIErrorReply) error { + *reply = APIErrorReply{ + Error: api.api.DeleteUser(args), + } + return nil +} + +func (api *LocalAPI) GetUser(args string, reply *APIUserReply) error { + user, err := api.api.GetUser(args) + *reply = APIUserReply{ + User: user, + Error: err, + } + return nil +} + +func (api *LocalAPI) GetUserByEmail(args string, reply *APIUserReply) error { + user, err := api.api.GetUserByEmail(args) + *reply = APIUserReply{ + User: user, + Error: err, + } + return nil +} + func (api *LocalAPI) GetUserByUsername(args string, reply *APIUserReply) error { user, err := api.api.GetUserByUsername(args) *reply = APIUserReply{ @@ -56,16 +128,59 @@ func (api *LocalAPI) GetUserByUsername(args string, reply *APIUserReply) error { return nil } +func (api *LocalAPI) UpdateUser(args *model.User, reply *APIUserReply) error { + user, err := api.api.UpdateUser(args) + *reply = APIUserReply{ + User: user, + Error: err, + } + return nil +} + type APIGetChannelByNameArgs struct { Name string TeamId string } +type APIGetDirectChannelArgs struct { + UserId1 string + UserId2 string +} + +type APIGetGroupChannelArgs struct { + UserIds []string +} + type APIChannelReply struct { Channel *model.Channel Error *model.AppError } +func (api *LocalAPI) CreateChannel(args *model.Channel, reply *APIChannelReply) error { + channel, err := api.api.CreateChannel(args) + *reply = APIChannelReply{ + Channel: channel, + Error: err, + } + return nil +} + +func (api *LocalAPI) DeleteChannel(args string, reply *APIErrorReply) error { + *reply = APIErrorReply{ + Error: api.api.DeleteChannel(args), + } + return nil +} + +func (api *LocalAPI) GetChannel(args string, reply *APIChannelReply) error { + channel, err := api.api.GetChannel(args) + *reply = APIChannelReply{ + Channel: channel, + Error: err, + } + return nil +} + func (api *LocalAPI) GetChannelByName(args *APIGetChannelByNameArgs, reply *APIChannelReply) error { channel, err := api.api.GetChannelByName(args.Name, args.TeamId) *reply = APIChannelReply{ @@ -75,6 +190,33 @@ func (api *LocalAPI) GetChannelByName(args *APIGetChannelByNameArgs, reply *APIC return nil } +func (api *LocalAPI) GetDirectChannel(args *APIGetDirectChannelArgs, reply *APIChannelReply) error { + channel, err := api.api.GetDirectChannel(args.UserId1, args.UserId2) + *reply = APIChannelReply{ + Channel: channel, + Error: err, + } + return nil +} + +func (api *LocalAPI) GetGroupChannel(args *APIGetGroupChannelArgs, reply *APIChannelReply) error { + channel, err := api.api.GetGroupChannel(args.UserIds) + *reply = APIChannelReply{ + Channel: channel, + Error: err, + } + return nil +} + +func (api *LocalAPI) UpdateChannel(args *model.Channel, reply *APIChannelReply) error { + channel, err := api.api.UpdateChannel(args) + *reply = APIChannelReply{ + Channel: channel, + Error: err, + } + return nil +} + type APIPostReply struct { Post *model.Post Error *model.AppError @@ -89,6 +231,31 @@ func (api *LocalAPI) CreatePost(args *model.Post, reply *APIPostReply) error { return nil } +func (api *LocalAPI) DeletePost(args string, reply *APIErrorReply) error { + *reply = APIErrorReply{ + Error: api.api.DeletePost(args), + } + return nil +} + +func (api *LocalAPI) GetPost(args string, reply *APIPostReply) error { + post, err := api.api.GetPost(args) + *reply = APIPostReply{ + Post: post, + Error: err, + } + return nil +} + +func (api *LocalAPI) UpdatePost(args *model.Post, reply *APIPostReply) error { + post, err := api.api.UpdatePost(args) + *reply = APIPostReply{ + Post: post, + Error: err, + } + return nil +} + func ServeAPI(api plugin.API, conn io.ReadWriteCloser, muxer *Muxer) { server := rpc.NewServer() server.Register(&LocalAPI{ @@ -113,12 +280,36 @@ func (api *RemoteAPI) LoadPluginConfiguration(dest interface{}) error { return json.Unmarshal(config, dest) } -func (api *RemoteAPI) GetTeamByName(name string) (*model.Team, *model.AppError) { - var reply APITeamReply - if err := api.client.Call("LocalAPI.GetTeamByName", name, &reply); err != nil { - return nil, model.NewAppError("RemoteAPI.GetTeamByName", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) +func (api *RemoteAPI) CreateUser(user *model.User) (*model.User, *model.AppError) { + var reply APIUserReply + if err := api.client.Call("LocalAPI.CreateUser", user, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.CreateUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) } - return reply.Team, reply.Error + return reply.User, reply.Error +} + +func (api *RemoteAPI) DeleteUser(userId string) *model.AppError { + var reply APIErrorReply + if err := api.client.Call("LocalAPI.DeleteUser", userId, &reply); err != nil { + return model.NewAppError("RemoteAPI.DeleteUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Error +} + +func (api *RemoteAPI) GetUser(userId string) (*model.User, *model.AppError) { + var reply APIUserReply + if err := api.client.Call("LocalAPI.GetUser", userId, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.User, reply.Error +} + +func (api *RemoteAPI) GetUserByEmail(email string) (*model.User, *model.AppError) { + var reply APIUserReply + if err := api.client.Call("LocalAPI.GetUserByEmail", email, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetUserByEmail", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.User, reply.Error } func (api *RemoteAPI) GetUserByUsername(name string) (*model.User, *model.AppError) { @@ -129,6 +320,78 @@ func (api *RemoteAPI) GetUserByUsername(name string) (*model.User, *model.AppErr return reply.User, reply.Error } +func (api *RemoteAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) { + var reply APIUserReply + if err := api.client.Call("LocalAPI.UpdateUser", user, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.UpdateUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.User, reply.Error +} + +func (api *RemoteAPI) CreateTeam(team *model.Team) (*model.Team, *model.AppError) { + var reply APITeamReply + if err := api.client.Call("LocalAPI.CreateTeam", team, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.CreateTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Team, reply.Error +} + +func (api *RemoteAPI) DeleteTeam(teamId string) *model.AppError { + var reply APIErrorReply + if err := api.client.Call("LocalAPI.DeleteTeam", teamId, &reply); err != nil { + return model.NewAppError("RemoteAPI.DeleteTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Error +} + +func (api *RemoteAPI) GetTeam(teamId string) (*model.Team, *model.AppError) { + var reply APITeamReply + if err := api.client.Call("LocalAPI.GetTeam", teamId, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Team, reply.Error +} + +func (api *RemoteAPI) GetTeamByName(name string) (*model.Team, *model.AppError) { + var reply APITeamReply + if err := api.client.Call("LocalAPI.GetTeamByName", name, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetTeamByName", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Team, reply.Error +} + +func (api *RemoteAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) { + var reply APITeamReply + if err := api.client.Call("LocalAPI.UpdateTeam", team, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.UpdateTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Team, reply.Error +} + +func (api *RemoteAPI) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { + var reply APIChannelReply + if err := api.client.Call("LocalAPI.CreateChannel", channel, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.CreateChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Channel, reply.Error +} + +func (api *RemoteAPI) DeleteChannel(channelId string) *model.AppError { + var reply APIErrorReply + if err := api.client.Call("LocalAPI.DeleteChannel", channelId, &reply); err != nil { + return model.NewAppError("RemoteAPI.DeleteChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Error +} + +func (api *RemoteAPI) GetChannel(channelId string) (*model.Channel, *model.AppError) { + var reply APIChannelReply + if err := api.client.Call("LocalAPI.GetChannel", channelId, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Channel, reply.Error +} + func (api *RemoteAPI) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) { var reply APIChannelReply if err := api.client.Call("LocalAPI.GetChannelByName", &APIGetChannelByNameArgs{ @@ -140,6 +403,35 @@ func (api *RemoteAPI) GetChannelByName(name, teamId string) (*model.Channel, *mo return reply.Channel, reply.Error } +func (api *RemoteAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) { + var reply APIChannelReply + if err := api.client.Call("LocalAPI.GetDirectChannel", &APIGetDirectChannelArgs{ + UserId1: userId1, + UserId2: userId2, + }, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetDirectChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Channel, reply.Error +} + +func (api *RemoteAPI) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) { + var reply APIChannelReply + if err := api.client.Call("LocalAPI.GetGroupChannel", &APIGetGroupChannelArgs{ + UserIds: userIds, + }, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetGroupChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Channel, reply.Error +} + +func (api *RemoteAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) { + var reply APIChannelReply + if err := api.client.Call("LocalAPI.UpdateChannel", channel, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.UpdateChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Channel, reply.Error +} + func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) { var reply APIPostReply if err := api.client.Call("LocalAPI.CreatePost", post, &reply); err != nil { @@ -148,6 +440,30 @@ func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError return reply.Post, reply.Error } +func (api *RemoteAPI) DeletePost(postId string) *model.AppError { + var reply APIErrorReply + if err := api.client.Call("LocalAPI.DeletePost", postId, &reply); err != nil { + return model.NewAppError("RemoteAPI.DeletePost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Error +} + +func (api *RemoteAPI) GetPost(postId string) (*model.Post, *model.AppError) { + var reply APIPostReply + if err := api.client.Call("LocalAPI.GetPost", postId, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.GetPost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Post, reply.Error +} + +func (api *RemoteAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) { + var reply APIPostReply + if err := api.client.Call("LocalAPI.UpdatePost", post, &reply); err != nil { + return nil, model.NewAppError("RemoteAPI.UpdatePost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError) + } + return reply.Post, reply.Error +} + func (h *RemoteAPI) Close() error { return h.client.Close() } |