2017-10-06 10:44:55 +00:00
|
|
|
package shop
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2017-10-06 10:44:55 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
)
|
|
|
|
|
|
|
|
// PurchaseHistory ...
|
2019-06-01 04:55:49 +00:00
|
|
|
func PurchaseHistory(ctx aero.Context) error {
|
2019-11-17 07:59:34 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2017-10-06 10:44:55 +00:00
|
|
|
|
|
|
|
if user == nil {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusUnauthorized, "Not logged in")
|
2017-10-06 10:44:55 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 18:03:24 +00:00
|
|
|
purchases, err := arn.FilterPurchases(func(purchase *arn.Purchase) bool {
|
|
|
|
return purchase.UserID == user.ID
|
|
|
|
})
|
2017-10-06 10:44:55 +00:00
|
|
|
|
|
|
|
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.PurchaseHistory(purchases, user))
|
|
|
|
}
|