// 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) } }