30 lines
804 B
Go
Raw Normal View History

2018-04-10 20:12:32 +00:00
package history
import (
"net/http"
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-04-10 20:12:32 +00:00
)
// Handler returns a function that renders the history of any object.
2019-06-01 04:55:49 +00:00
func Handler(render func(interface{}, []*arn.EditLogEntry, *arn.User) string, typeNames ...string) func(ctx aero.Context) error {
return func(ctx aero.Context) error {
2018-04-10 20:12:32 +00:00
id := ctx.Get("id")
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-04-10 20:12:32 +00:00
obj, err := arn.DB.Get(typeNames[0], id)
if err != nil {
return ctx.Error(http.StatusNotFound, typeNames[0]+" not found", err)
}
entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool {
return entry.ObjectID == id && arn.Contains(typeNames, entry.ObjectType)
})
arn.SortEditLogEntriesLatestFirst(entries)
return ctx.HTML(render(obj, entries, user))
}
}