37 lines
788 B
Go
Raw Normal View History

2017-10-07 21:24:09 +00:00
package admin
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// PurchaseHistory ...
func PurchaseHistory(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not logged in")
2017-10-07 21:24:09 +00:00
}
if user.Role != "admin" {
2018-07-07 03:42:00 +00:00
return ctx.Error(http.StatusUnauthorized, "Not authorized")
2017-10-07 21:24:09 +00:00
}
purchases, err := arn.AllPurchases()
if err != nil {
return ctx.Error(http.StatusInternalServerError, "Error fetching shop item data", err)
}
sort.Slice(purchases, func(i, j int) bool {
return purchases[i].Date > purchases[j].Date
})
return ctx.HTML(components.GlobalPurchaseHistory(purchases))
}