2018-03-26 21:38:15 +00:00
|
|
|
package explorerelations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"sort"
|
|
|
|
|
|
|
|
"github.com/animenotifier/arn"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Sequels ...
|
2019-06-01 04:55:49 +00:00
|
|
|
func Sequels(ctx aero.Context) error {
|
2018-12-06 05:13:49 +00:00
|
|
|
nick := ctx.Get("nick")
|
2018-03-26 21:38:15 +00:00
|
|
|
user := utils.GetUser(ctx)
|
2018-12-06 05:13:49 +00:00
|
|
|
viewUser, err := arn.GetUserByNick(nick)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
animeList := viewUser.AnimeList()
|
2018-03-26 21:38:15 +00:00
|
|
|
sequels := []*utils.AnimeWithRelatedAnime{}
|
|
|
|
|
|
|
|
for anime := range arn.StreamAnime() {
|
2018-03-26 21:42:54 +00:00
|
|
|
item := animeList.Find(anime.ID)
|
|
|
|
|
|
|
|
// Ignore if user added the anime and it's not "Planned" status
|
|
|
|
if item != nil && item.Status != arn.AnimeListStatusPlanned {
|
2018-03-26 21:38:15 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
prequels := anime.Prequels()
|
|
|
|
|
|
|
|
for _, prequel := range prequels {
|
|
|
|
item := animeList.Find(prequel.ID)
|
|
|
|
|
|
|
|
if item != nil && item.Status == arn.AnimeListStatusCompleted {
|
|
|
|
sequels = append(sequels, &utils.AnimeWithRelatedAnime{
|
|
|
|
Anime: anime,
|
|
|
|
Related: prequel,
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Slice(sequels, func(i, j int) bool {
|
|
|
|
aScore := sequels[i].Anime.Score()
|
|
|
|
bScore := sequels[j].Anime.Score()
|
|
|
|
|
|
|
|
if aScore == bScore {
|
|
|
|
return sequels[i].Anime.Title.Canonical < sequels[j].Anime.Title.Canonical
|
|
|
|
}
|
|
|
|
|
|
|
|
return aScore > bScore
|
|
|
|
})
|
|
|
|
|
2018-12-06 05:13:49 +00:00
|
|
|
return ctx.HTML(components.ExploreAnimeSequels(sequels, viewUser, user))
|
2018-03-26 21:38:15 +00:00
|
|
|
}
|