46 lines
1.1 KiB
Go
Raw Normal View History

2017-07-05 14:52:24 +00:00
package animelist
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// FilterByStatus returns a handler for the given anime list item status.
func FilterByStatus(status string) aero.Handle {
return func(ctx *aero.Context) string {
user := utils.GetUser(ctx)
list, response := statusList(ctx, status)
if response != "" {
return response
}
2017-07-22 13:04:54 +00:00
return ctx.HTML(components.ProfileAnimeListFilteredByStatus(list, list.User(), user, status, ctx.URI()))
2017-07-05 14:52:24 +00:00
}
}
// statusList handles the request for an anime list with a given status.
func statusList(ctx *aero.Context, status string) (*arn.AnimeList, string) {
nick := ctx.Get("nick")
viewUser, err := arn.GetUserByNick(nick)
if err != nil {
return nil, ctx.Error(http.StatusNotFound, "User not found", err)
}
animeList := viewUser.AnimeList()
if animeList == nil {
return nil, ctx.Error(http.StatusNotFound, "Anime list not found", nil)
}
watchingList := animeList.FilterStatus(status)
watchingList.Sort()
return watchingList, ""
}