Show sequels of completed anime
This commit is contained in:
57
pages/explore/explorerelations/sequels.go
Normal file
57
pages/explore/explorerelations/sequels.go
Normal file
@ -0,0 +1,57 @@
|
||||
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 ...
|
||||
func Sequels(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
if user == nil {
|
||||
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
|
||||
}
|
||||
|
||||
animeList := user.AnimeList()
|
||||
sequels := []*utils.AnimeWithRelatedAnime{}
|
||||
|
||||
for anime := range arn.StreamAnime() {
|
||||
if animeList.Contains(anime.ID) {
|
||||
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
|
||||
})
|
||||
|
||||
return ctx.HTML(components.ExploreAnimeSequels(sequels, user))
|
||||
}
|
Reference in New Issue
Block a user