diff options
author | Carlos Tadeu Panato Junior <ctadeu@gmail.com> | 2017-03-24 18:23:32 +0100 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2017-03-24 17:23:32 +0000 |
commit | 5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5 (patch) | |
tree | 19445c4de5d31670ede7429a97e292b72c022368 /api4/status.go | |
parent | 28ad645153b206ba84ddc4935280eaed94bb0138 (diff) | |
download | chat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.tar.gz chat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.tar.bz2 chat-5bf6ae04dfedc2e504ea8af5c71b2e9a8287e2b5.zip |
[APIV4] GET /users/{user_id}/status - user status endpoint for apiV4 (#5824)
Diffstat (limited to 'api4/status.go')
-rw-r--r-- | api4/status.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/api4/status.go b/api4/status.go new file mode 100644 index 000000000..5cd6a4536 --- /dev/null +++ b/api4/status.go @@ -0,0 +1,40 @@ +// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api4 + +import ( + "net/http" + + l4g "github.com/alecthomas/log4go" + + "github.com/mattermost/platform/app" + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func InitStatus() { + l4g.Debug(utils.T("api.status.init.debug")) + + BaseRoutes.User.Handle("/status", ApiHandler(getUserStatus)).Methods("GET") + +} + +func getUserStatus(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireUserId() + if c.Err != nil { + return + } + + if statusMap, err := app.GetUserStatusesByIds([]string{c.Params.UserId}); err != nil { + c.Err = err + return + } else { + if len(statusMap) == 0 { + c.Err = model.NewAppError("UserStatus", "api.status.user_not_found.app_error", nil, "", http.StatusNotFound) + return + } else { + w.Write([]byte(statusMap[0].ToJson())) + } + } +} |