// HandleCreateShow serves the create form via GET for posts func HandleCreateShow(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Find users for author details users, err := users.FindAll(users.Admins()) if err != nil { return router.NotFoundError(err) } // Render the template view := view.New(context) post := posts.New() user := authorise.CurrentUser(context) if user != nil { post.AuthorId = user.Id } view.AddKey("post", post) view.AddKey("users", users) return view.Render() }
// HandleUpdateShow renders the form to update a post func HandleUpdateShow(context router.Context) error { // Find the post post, err := posts.Find(context.ParamInt("id")) if err != nil { return router.NotFoundError(err) } // Authorise update post err = authorise.Resource(context, post) if err != nil { return router.NotAuthorizedError(err) } // Find users for author details users, err := users.FindAll(users.Admins()) if err != nil { return router.NotFoundError(err) } // Render the template view := view.New(context) view.AddKey("post", post) view.AddKey("users", users) return view.Render() }
// HandleIndex serves a GET request at /users func HandleIndex(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Fetch the users q := users.Query().Order("name asc") userList, err := users.FindAll(q) if err != nil { context.Logf("#error Error indexing users %s", err) return router.InternalError(err) } // Serve template view := view.New(context) view.AddKey("users", userList) return view.Render() }