From 6ff350380b209266282cff32872f94bb9cd31d57 Mon Sep 17 00:00:00 2001 From: Andrei Stanciu Date: Tue, 28 Feb 2017 11:34:32 +0200 Subject: ApiV4: PUT /posts/{post_id} (#5521) --- api4/post.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'api4/post.go') diff --git a/api4/post.go b/api4/post.go index 6a8b1bff2..4632cb6df 100644 --- a/api4/post.go +++ b/api4/post.go @@ -24,6 +24,7 @@ func InitPost() { BaseRoutes.PostsForChannel.Handle("", ApiSessionRequired(getPostsForChannel)).Methods("GET") BaseRoutes.Team.Handle("/posts/search", ApiSessionRequired(searchPosts)).Methods("POST") + BaseRoutes.Post.Handle("", ApiSessionRequired(updatePost)).Methods("PUT") } func createPost(c *Context, w http.ResponseWriter, r *http.Request) { @@ -176,6 +177,31 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(posts.ToJson())) } +func updatePost(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequirePostId() + post := model.PostFromJson(r.Body) + + if post == nil { + c.SetInvalidParam("post") + return + } + + if !app.SessionHasPermissionToChannelByPost(c.Session, c.Params.PostId, model.PERMISSION_EDIT_POST) { + c.SetPermissionError(model.PERMISSION_EDIT_POST) + return + } + + post.UserId = c.Session.UserId + + rpost, err := app.UpdatePost(post) + if err != nil { + c.Err = err + return + } + + w.Write([]byte(rpost.ToJson())) +} + func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { c.RequirePostId() if c.Err != nil { @@ -198,3 +224,4 @@ func getFileInfosForPost(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(model.FileInfosToJson(infos))) } } + -- cgit v1.2.3-1-g7c22