Skip to content

Commit

Permalink
Sort moderation logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
humaidq committed Aug 14, 2020
1 parent 22e7953 commit 69d4b61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions models/moderation_sort.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package models

import (
"time"
)

// ModerationSort implements sort.Interface for []Moderation depending on date.
type ModerationSort []Moderation

func (p ModerationSort) Len() int {
return len(p)
}

func (p ModerationSort) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}

func (p ModerationSort) Less(i, j int) bool {
return time.Unix(p[i].CreatedUnix, 0).After(time.Unix(p[j].CreatedUnix, 0))
}
5 changes: 4 additions & 1 deletion routes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package routes
import (
"bytes"
"log"
"sort"

"github.com/hw-cs-reps/platform/config"
"github.com/hw-cs-reps/platform/models"
Expand All @@ -25,7 +26,9 @@ func HomepageHandler(ctx *macaron.Context, sess session.Store, f *session.Flash)
// ModLogsHandler response for the moderation log page.
func ModLogsHandler(ctx *macaron.Context, sess session.Store, f *session.Flash) {
ctx.Data["Title"] = "Moderation Log"
ctx.Data["Logs"] = models.GetModerations()
logs := models.GetModerations()
sort.Sort(models.ModerationSort(logs))
ctx.Data["Logs"] = logs
ctx.HTML(200, "moderations")
}

Expand Down

0 comments on commit 69d4b61

Please sign in to comment.