github.com/gigforks/mattermost-server@v4.9.1-0.20180619094218-800d97fa55d0+incompatible/api/status.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package api 5 6 import ( 7 "net/http" 8 9 "github.com/mattermost/mattermost-server/model" 10 ) 11 12 func (api *API) InitStatus() { 13 api.BaseRoutes.Users.Handle("/status", api.ApiUserRequired(getStatusesHttp)).Methods("GET") 14 api.BaseRoutes.Users.Handle("/status/ids", api.ApiUserRequired(getStatusesByIdsHttp)).Methods("POST") 15 } 16 17 func getStatusesHttp(c *Context, w http.ResponseWriter, r *http.Request) { 18 statusMap := model.StatusMapToInterfaceMap(c.App.GetAllStatuses()) 19 w.Write([]byte(model.StringInterfaceToJson(statusMap))) 20 } 21 22 func getStatusesByIdsHttp(c *Context, w http.ResponseWriter, r *http.Request) { 23 userIds := model.ArrayFromJson(r.Body) 24 25 if len(userIds) == 0 { 26 c.SetInvalidParam("getStatusesByIdsHttp", "user_ids") 27 return 28 } 29 30 statusMap, err := c.App.GetStatusesByIds(userIds) 31 if err != nil { 32 c.Err = err 33 return 34 } 35 36 w.Write([]byte(model.StringInterfaceToJson(statusMap))) 37 }