This commit is contained in:
Eduard Urbach 2018-03-14 20:22:21 +01:00
parent 7b10997ef6
commit c67fad8f60

View File

@ -1,45 +1,36 @@
package animelist package animelist
import ( // // ProfileFilterByStatus returns a handler for the given anime list item status.
"net/http" // func ProfileFilterByStatus(status string) aero.Handle {
// return func(ctx *aero.Context) string {
// user := utils.GetUser(ctx)
// list, response := statusList(ctx, status)
"github.com/aerogo/aero" // if response != "" {
"github.com/animenotifier/arn" // return response
"github.com/animenotifier/notify.moe/components" // }
"github.com/animenotifier/notify.moe/utils"
)
// ProfileFilterByStatus returns a handler for the given anime list item status. // return ctx.HTML(components.ProfileAnimeListItems(list.Items, list.User(), user, status, ctx.URI()))
func ProfileFilterByStatus(status string) aero.Handle { // }
return func(ctx *aero.Context) string { // }
user := utils.GetUser(ctx)
list, response := statusList(ctx, status)
if response != "" { // // statusList handles the request for an anime list with a given status.
return response // func statusList(ctx *aero.Context, status string) (*arn.AnimeList, string) {
} // nick := ctx.Get("nick")
// viewUser, err := arn.GetUserByNick(nick)
return ctx.HTML(components.ProfileAnimeListItems(list.Items, list.User(), user, status, ctx.URI())) // if err != nil {
} // return nil, ctx.Error(http.StatusNotFound, "User not found", err)
} // }
// statusList handles the request for an anime list with a given status. // animeList := viewUser.AnimeList()
func statusList(ctx *aero.Context, status string) (*arn.AnimeList, string) {
nick := ctx.Get("nick")
viewUser, err := arn.GetUserByNick(nick)
if err != nil { // if animeList == nil {
return nil, ctx.Error(http.StatusNotFound, "User not found", err) // return nil, ctx.Error(http.StatusNotFound, "Anime list not found", nil)
} // }
animeList := viewUser.AnimeList() // watchingList := animeList.FilterStatus(status)
// watchingList.Sort()
if animeList == nil { // return watchingList, ""
return nil, ctx.Error(http.StatusNotFound, "Anime list not found", nil) // }
}
watchingList := animeList.FilterStatus(status)
watchingList.Sort()
return watchingList, ""
}