func TestAddEditDeleteProjectPostComment(t *testing.T) { myProject := me.Projects()[0] projectPostList := *myProject.Postlist(nerdz.PostlistOptions{N: 1}) projectPost := projectPostList[0].(*nerdz.ProjectPost) var projectPostComment nerdz.ProjectPostComment projectPostComment.Hpid = projectPost.Hpid projectPostComment.Message = "lol k" if err := me.Add(&projectPostComment); err != nil { t.Fatalf("Add comment on an existing project post sould work but failed with error: %s", err.Error()) } projectPostComment.Message = "lol, k" // Wait 5 second to avoid flood limit (db side) time.Sleep(5000 * time.Millisecond) if err := me.Edit(&projectPostComment); err != nil { t.Fatalf("Edit project post comment failed with error: %s", err) } if err := me.Delete(&projectPostComment); err != nil { t.Fatalf("Delete with hcid %v shoud work, but got error: %v", projectPostComment.Hcid, err) } }
// NewPostComment handles the request and creates a new post func NewPostComment() echo.HandlerFunc { // swagger:route POST /projects/{id}/posts/{pid}/comments project post comment NewProjectPostComment // // Creates a new post on the specified project board // // Consumes: // - application/json // // Produces: // - application/json // // Security: // oauth: project_comments:write // // Responses: // default: apiResponse return func(c echo.Context) error { if !rest.IsGranted("project_comments:write", c) { return rest.InvalidScopeResponse("project_comments:write", c) } // Read a rest.Message from the body request. message := rest.NewMessage{} if err := c.Bind(&message); err != nil { return err } // Create a nerdz.ProjectPostComment from the message // and current context. comment := nerdz.ProjectPostComment{} comment.Message = message.Message comment.Lang = message.Lang comment.To = c.Get("project").(*nerdz.Project).ID() comment.Hpid = c.Get("post").(*nerdz.ProjectPost).ID() // Send it me := c.Get("me").(*nerdz.User) if err := me.Add(&comment); err != nil { return err } // Extract the TO from the new post and return // selected fields. return rest.SelectFields(comment.GetTO(me), c) } }