41 lines
851 B
Go
Raw Normal View History

2017-10-17 21:17:04 +00:00
package groups
import (
"net/http"
2017-10-18 16:18:15 +00:00
"sort"
2017-10-17 21:17:04 +00:00
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
2017-10-18 16:18:15 +00:00
const groupsPerPage = 12
2017-10-17 21:17:04 +00:00
// Get ...
func Get(ctx *aero.Context) string {
user := utils.GetUser(ctx)
groups, err := arn.FilterGroups(func(group *arn.Group) bool {
return !group.IsDraft
})
2017-10-18 16:18:15 +00:00
sort.Slice(groups, func(i, j int) bool {
if len(groups[i].Members) == len(groups[j].Members) {
return groups[i].Created > groups[j].Created
}
return len(groups[i].Members) > len(groups[j].Members)
})
if len(groups) > groupsPerPage {
groups = groups[:groupsPerPage]
}
2017-10-17 21:17:04 +00:00
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching groups", err)
}
2017-10-18 16:18:15 +00:00
return ctx.HTML(components.Groups(groups, groupsPerPage, user))
2017-10-17 21:17:04 +00:00
}