// DeleteProjectFollowing handles the request and deletes the target project from the current list following list func DeleteProjectFollowing() echo.HandlerFunc { // swagger:route DELETE /me/following/users/{target} user DeleteProjectFollowing // // Deletes target project from the current user following list // // Consumes: // - application/json // // Security: // oauth: following:write // // Responses: // default: apiResponse return func(c echo.Context) error { if !rest.IsGranted("following:write", c) { return rest.InvalidScopeResponse("following:write", c) } var target *nerdz.Project var err error if target, err = rest.Project("target", c); err != nil { return err } me := c.Get("me").(*nerdz.User) if err = me.Unfollow(target); err != nil { errstr := err.Error() c.JSON(http.StatusBadRequest, &rest.Response{ Data: nil, HumanMessage: errstr, Message: errstr, Status: http.StatusBadRequest, Success: false, }) return errors.New(errstr) } message := "Success" c.JSON(http.StatusOK, &rest.Response{ Data: nil, HumanMessage: message, Message: message, Status: http.StatusOK, Success: true, }) return nil } }
// SetProject is the middleware that checks if the current logged user can see the required project // and if the required project exists. On success sets the "project" = *Project variable in the context func SetProject() echo.MiddlewareFunc { return func(next echo.HandlerFunc) echo.HandlerFunc { return echo.HandlerFunc(func(c echo.Context) error { var project *nerdz.Project var err error if project, err = rest.Project("id", c); err != nil { return err } // store the project Project into the context c.Set("project", project) // pass context to the next handler return next(c) }) } }
// NewProjectFollowing handles the request and creates and adds target to the following list of the current user func NewProjectFollowing() echo.HandlerFunc { // swagger:route POST /me/following/projects/{target} project following NewProjectFollowing // // Adds target project to the following list of the current user // // Produces: // - application/json // // Security: // oauth: following:write // // Responses: // default: apiResponse return func(c echo.Context) error { if !rest.IsGranted("following:write", c) { return rest.InvalidScopeResponse("following:write", c) } var target *nerdz.Project var err error if target, err = rest.Project("target", c); err != nil { return err } me := c.Get("me").(*nerdz.User) if err = me.Follow(target); err != nil { errstr := err.Error() c.JSON(http.StatusBadRequest, &rest.Response{ Data: nil, HumanMessage: errstr, Message: errstr, Status: http.StatusBadRequest, Success: false, }) return errors.New(errstr) } // Return selected field from the followed Project return rest.SelectFields(target.GetTO(me), c) } }