This repository has been archived on 2022-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
gosocial/pkg/controller/forum/manage.go
Noah Petherbridge a663462e27 Forums: Basic Support WIP
Adds initial code for basically functional forums:

* Forums landing page shows hard-coded list of Categories along with any
  forums in the DB that use those categories.
* Admin: Create, Edit forums and view forums you own or have admin rights
  to modify.
* Landing page forums list shows the title/description and dynamic count of
  number of Topics and total number of Posts in each forum. TODO: distinct
  count of Users who posted in each forum.
* Board Index page shows list of Threads (posts) with a Replies count and
  Views count on each thread.
* Thread view is basically an array of Comments. Users can post, edit and
  delete (their own) comments. Deleting the first comment removes the
  entire Thread - the thread points to a first Comment to provide its body.
* Reply and Quote-Reply options working.
2022-08-23 22:55:19 -07:00

49 lines
1.2 KiB
Go

package forum
import (
"net/http"
"git.kirsle.net/apps/gosocial/pkg/config"
"git.kirsle.net/apps/gosocial/pkg/models"
"git.kirsle.net/apps/gosocial/pkg/session"
"git.kirsle.net/apps/gosocial/pkg/templates"
)
// Manage page for forums -- admin only for now but may open up later.
func Manage() http.HandlerFunc {
tmpl := templates.Must("forum/admin.html")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Get the current user.
currentUser, err := session.CurrentUser(r)
if err != nil {
session.FlashError(w, r, "Couldn't get current user: %s", err)
templates.Redirect(w, "/")
return
}
// Get forums the user owns or can manage.
var pager = &models.Pagination{
Page: 1,
PerPage: config.PageSizeForumAdmin,
Sort: "updated_at desc",
}
pager.ParsePage(r)
forums, err := models.PaginateOwnedForums(currentUser.ID, currentUser.IsAdmin, pager)
if err != nil {
session.FlashError(w, r, "Couldn't paginate owned forums: %s", err)
templates.Redirect(w, "/")
return
}
var vars = map[string]interface{}{
"Pager": pager,
"Forums": forums,
}
if err := tmpl.Execute(w, r, vars); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})
}