Added route showing all notifications

This commit is contained in:
2018-03-01 23:18:29 +01:00
parent 40ea58dffe
commit 700bf089bf
4 changed files with 43 additions and 4 deletions

View File

@ -13,8 +13,8 @@ import (
const maxNotifications = 30
// All shows all notifications sent so far.
func All(ctx *aero.Context) string {
// ByUser shows all notifications sent to the given user.
func ByUser(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
@ -44,3 +44,24 @@ func All(ctx *aero.Context) string {
return ctx.HTML(components.Notifications(notifications, viewUser, user))
}
// All shows all notifications.
func All(ctx *aero.Context) string {
notifications, err := arn.AllNotifications()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Could not retrieve notification list", err)
}
// Sort by date
sort.Slice(notifications, func(i, j int) bool {
return notifications[i].Created > notifications[j].Created
})
// Limit results
if len(notifications) > maxNotifications {
notifications = notifications[:maxNotifications]
}
return ctx.HTML(components.AllNotifications(notifications))
}